Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





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.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 07-20-2007, 04:59 AM
Member
 
Join Date: Jul 2007
Posts: 2
cplmckenzie is on a distinguished road
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,
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 07-20-2007, 05:09 AM
Member
 
Join Date: Jul 2007
Posts: 41
fred is on a distinguished road
did you get some exception? or any error?
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 07-20-2007, 05:35 AM
Member
 
Join Date: Jul 2007
Posts: 2
cplmckenzie is on a distinguished road
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,
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 08-09-2007, 11:42 PM
Member
 
Join Date: Jul 2007
Posts: 43
leonard is on a distinguished road
please paste the code, probably the problem is in it
Bookmark Post in Technorati
Reply With Quote
  #5 (permalink)  
Old 11-05-2007, 02:42 PM
Member
 
Join Date: Nov 2007
Posts: 2
daheri is on a distinguished road
Quote:
Originally Posted by cplmckenzie View Post
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.
Bookmark Post in Technorati
Reply With Quote
  #6 (permalink)  
Old 01-02-2008, 02:55 PM
Member
 
Join Date: Dec 2007
Posts: 28
anki1234 is on a distinguished road
paste the code . May be u are not able to provide proper parameter in query corresponding to which u r making search
Bookmark Post in Technorati
Reply With Quote
  #7 (permalink)  
Old 04-22-2008, 03:48 AM
Member
 
Join Date: Apr 2008
Posts: 28
rico16135 is on a distinguished road
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.
Bookmark Post in Technorati
Reply With Quote
  #8 (permalink)  
Old 04-22-2008, 12:18 PM
DonCash's Avatar
Moderator
 
Join Date: Aug 2007
Location: London, UK
Posts: 237
DonCash will become famous soon enoughDonCash will become famous soon enough
Have you constructed the query string correctly?
Code:
"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.
Bookmark Post in Technorati
Reply With Quote
  #9 (permalink)  
Old 04-22-2008, 12:30 PM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 2,338
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
Quote:
Originally Posted by DonCash View Post
Code:
"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.
Bookmark Post in Technorati
Reply With Quote
  #10 (permalink)  
Old 04-22-2008, 01:03 PM
Member
 
Join Date: Apr 2008
Posts: 91
javarishi is on a distinguished road
Hei Eranga, You have pointed out the error.
Bookmark Post in Technorati
Reply With Quote
  #11 (permalink)  
Old 04-22-2008, 01:54 PM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 2,338
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
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.
Bookmark Post in Technorati
Reply With Quote
  #12 (permalink)  
Old 04-22-2008, 02:15 PM
DonCash's Avatar
Moderator
 
Join Date: Aug 2007
Location: London, UK
Posts: 237
DonCash will become famous soon enoughDonCash will become famous soon enough
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.
Bookmark Post in Technorati
Reply With Quote
  #13 (permalink)  
Old 04-23-2008, 04:24 AM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 2,338
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
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.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Select Count Apple2 JavaServer Pages (JSP) and JSTL 1 04-29-2008 10:02 AM
JDBC select problem abhiN Database 0 03-12-2008 09:09 AM
Select specific cell Echilon New To Java 1 01-01-2008 08:47 AM
Internationalization: Select language from combo box alejandrgarcia AWT / Swing 0 08-11-2007 11:26 AM
How to select/highlight an entire row in JTextArea Valeriano AWT / Swing 2 05-28-2007 12:20 PM


All times are GMT +3. The time now is 02:57 AM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org