Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

executeQuery of ResultSet doesnt like WHERE clause

Status
Not open for further replies.

justgotpaid

Programmer
Jul 12, 2009
2
US
Hello all. Im trying to bring back a row of data from a mysql table based on a filename field which is a varchar datatype. But Im not using the actual string, which happens to be wav1.wav but a variable name which was assigned to the string, i.e. the str below. It doesnt like this. HOwever if I replace the str with: ....FILENAME = 'wav1.wav'") then its fine. Any clues? Using Java by the way.


ResultSet rs = stmt.executeQuery(
"SELECT FILENO,FILELOC,FILENAME FROM METADATA WHERE FILENAME=" + str);
 
I'd use a PreparedStatemet, that will prepare the query for you.

If not, you need to add que quotes yourself

Code:
ResultSet rs = stmt.executeQuery(
            "SELECT FILENO,FILELOC,FILENAME FROM METADATA WHERE FILENAME='" + str+"'");

Cheers,
Dian
 
Thanks Dian, actually I kinda should have known this cuz I used the same thing in a Insert statement and had to use all those, as you say, que quotes. I guess my question is you'd think that the designers of java would have something built into their sql statements to treat the + str which I had as the actual filename instead of having to put all those que quotes. What do u think?
S
 
Well, if the filename is always the same, a static String is the way to go.

If not, I'd use the static String for the query itself and a PreparedStatement to build it

Cheers,
Dian
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top