|
|
Welcome to the Java Forums.
You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:
- have access to post topics
- communicate privately with other members (PM)
- not see advertisements between posts
- have the possibility to earn one of our surprises if you are an active member
- access many other special features that will be introduced later.
Registration is fast, simple and absolutely free so please, join our community today!
If you have any problems with the registration process or your account login, please contact us.
|
|

07-20-2007, 04:59 AM
|
|
Member
|
|
Join Date: Jul 2007
Posts: 2
|
|
|
Using a variable in a SELECT FROM WHERE query
Hi,
I have a java web app that accesses a MySQL database.
It works well except that I am unable to to retrieve a rowset when I use
the WHERE clause with a variable... as in
SELECT * FROM tablename WHERE tablename.fieldname = variablename
Any help is appreciated
regards,
|
|

07-20-2007, 05:09 AM
|
|
Member
|
|
Join Date: Jul 2007
Posts: 41
|
|
|
did you get some exception? or any error?
|
|

07-20-2007, 05:35 AM
|
|
Member
|
|
Join Date: Jul 2007
Posts: 2
|
|
|
Using a variable in a SELECT FROM WHERE query
No. The query executed but it said "No Items Found" as though the variable was null.
I was attempting to change the query string in a SessionBean setcommand.Value
regards,
|
|

08-09-2007, 11:42 PM
|
|
Member
|
|
Join Date: Jul 2007
Posts: 43
|
|
|
please paste the code, probably the problem is in it
|
|

11-05-2007, 02:42 PM
|
|
Member
|
|
Join Date: Nov 2007
Posts: 2
|
|
Originally Posted by cplmckenzie
No. The query executed but it said "No Items Found" as though the variable was null.
Hey man,
"No Items Found" means exactly what it says. Your query has returned 0 rows.
In other words, either the table is empty, or your where clause is eliminating all results. Try running your query directly against the db to check.
|
|

01-02-2008, 02:55 PM
|
|
Member
|
|
Join Date: Dec 2007
Posts: 28
|
|
|
paste the code . May be u are not able to provide proper parameter in query corresponding to which u r making search
|
|

04-22-2008, 03:48 AM
|
|
Member
|
|
Join Date: Apr 2008
Posts: 28
|
|
|
Use PreparedStatement to create your query. leave a '?' in place of your variable to insert. then use the method set() in the PreparedStatement class to insert your variable. There are setInt, setString, etc. for whatever type you are using. You should read up on PreparedStatement as well as all the Statement classes to see how they are used, as well as to determine which one to use.
|
|

04-22-2008, 12:18 PM
|
 |
Moderator
|
|
Join Date: Aug 2007
Location: London, UK
Posts: 237
|
|
Have you constructed the query string correctly?
"SELECT * FROM " + tablename + " WHERE " + tablename.fieldname + " = " + variablename;
__________________
Did this post help you? Please To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts. me! To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts. || Don't forget to: To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts. To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Last edited by DonCash : 04-22-2008 at 12:21 PM.
|
|

04-22-2008, 12:30 PM
|
 |
Moderator
|
|
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 2,338
|
|
Originally Posted by DonCash
"SELECT * FROM " + tablename + " WHERE " + tablename.fieldname + " = " + variablename;
tablename.fieldname
Here need only the field/column name right? No need to use the table name here. 
__________________
Use an appropriate Subject. "Help, urgent!" isn't one. To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Has someone helped you? Then you can To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts. their helpful post.
Want to make your IDE the best? To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
|

04-22-2008, 01:03 PM
|
|
Member
|
|
Join Date: Apr 2008
Posts: 91
|
|
|
Hei Eranga, You have pointed out the error.
|
|

04-22-2008, 01:54 PM
|
 |
Moderator
|
|
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 2,338
|
|
It's not Java at all pal. Don may put it by a mistake 
__________________
Use an appropriate Subject. "Help, urgent!" isn't one. To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Has someone helped you? Then you can To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts. their helpful post.
Want to make your IDE the best? To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
|

04-22-2008, 02:15 PM
|
 |
Moderator
|
|
Join Date: Aug 2007
Location: London, UK
Posts: 237
|
|
|
I thought he had wrote a Java application to connect to a SQL database and that was his string query to the db being sent within the code. Nice one Eranga.
__________________
Did this post help you? Please To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts. me! To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts. || Don't forget to: To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts. To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
|

04-23-2008, 04:24 AM
|
 |
Moderator
|
|
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 2,338
|
|
Yes Don, I see that on our original post too. I'm just pointing that my friend. Such a little mistake can be make a huge damage at all. 
__________________
Use an appropriate Subject. "Help, urgent!" isn't one. To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Has someone helped you? Then you can To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts. their helpful post.
Want to make your IDE the best? To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|