Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: Pulling in data from access

  1. #1
    Junior Member
    Join Date
    Mar 2010
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Pulling in data from access

    Hi guys, I'm not only new to this forum but to java programming in general so if I make any glaring mistakes please bare with me.

    So, I'm currently writing a program that pulls in data from a database. I'm trying to make a barebones jukebox, so the idea is that I have a JFrame for seeing the entire song library, creating a playlist and updating track information. The database seems to have implemented Ok; there were a few problems but this was fixed using import java.sql.*; on each auxillary class.

    Here's the problem, in the database there is a field called "key"; the track number of each song. To look at the specifics of a certain song, or to update its information, or to add it to a playlist I need to type in the track number and hit the required button. For instance, if I were to want to check Brown Sugar by The Rolling Stones, I'd enter its track number in the text field (say '4'), click "info" and then I'd see the song name, artist, rating, play count etc. The only thing is I'm getting errors whenever I search for a song. If the program can't find the track then it simply outputs "No such track number". The output from the programming package says:

    java.sql.SQLException: [Microsoft][ODBC Microsoft Access Driver] Data type mismatch in criteria expression.

    Can anyone hazard a guess as to what the problem might be? This is really bugging me, and it's happening across the board - in every auxillary class. No tracks can be found.

    Thanks in advance.

    P.s. I should also note that in the main part of the jukebox, the library, the songs are actually showing up. So I know the program is contacting the database.
    Last edited by tdc5013; March 10th, 2010 at 11:53 AM.


  2. #2
    Junior Member
    Join Date
    Mar 2010
    Posts
    14
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default Re: Pulling in data from access

    I'm trying to learn data access with Java myself, but does this error indicate a problem with your search query? It sounds like the connection is being made just fine:
    I should also note that in the main part of the jukebox, the library, the songs are actually showing up. So I know the program is contacting the database.
    Can you post the code where you build your search query?

  3. #3
    Junior Member
    Join Date
    Mar 2010
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Pulling in data from access

    I managed to fix the problem. It turned out I had the "key" in the database as an AutoNumber, but everytime I was looking for it in the program I was using a String.

    My program now more or less works fine, except for one little thing. In the part of my program where I create a playlist I want a message saying "No such track" to appear in the main textfield (called "list) if the textbox where the user inputs the key (trackNumber) is empty, or has an unrecognised input; basically if it is 'null'.

    if (trackNumber == null)
    //If the number doesn't correspond to anything in the library...
    {
    list.setText("No such track number");
    //Display "No such track number" in the "information" text field
    }

    Except when testing this instead of the message I get "null - null".

    I found that the message did actually appear whenever I changed "trackNumber" to "name" in the If statement.

    ( String name = LibraryData.getName(key); - LibraryData is the part of the program interacting with the database )

    However, this then stops other parts of the program working - such as the reset function, which merely clears "list". The message "No such track number" just stays there.

    Any ideas?

Similar Threads

  1. access restriction??? wtf!?!
    By wolfgar in forum Java Theory & Questions
    Replies: 6
    Last Post: November 23rd, 2009, 07:27 AM
  2. Default Access (package access) confusion
    By gauravrajbehl in forum Java Theory & Questions
    Replies: 1
    Last Post: November 18th, 2009, 04:11 AM
  3. Access the Same Socket
    By ahmmnhwa in forum Java Networking
    Replies: 5
    Last Post: October 29th, 2009, 11:50 AM
  4. Random Access File
    By silver_unicorn in forum File I/O & Other I/O Streams
    Replies: 1
    Last Post: August 12th, 2009, 01:51 AM
  5. Random Access File
    By silver_unicorn in forum File I/O & Other I/O Streams
    Replies: 1
    Last Post: August 10th, 2009, 10:44 PM