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.
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:
Can you post the code where you build your search query?
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.
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.