Results 1 to 13 of 13
- 07-20-2007, 03:59 AM #1
Member
- Join Date
- Jul 2007
- Posts
- 2
- Rep Power
- 0
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, 04:09 AM #2
Member
- Join Date
- Jul 2007
- Posts
- 41
- Rep Power
- 0
did you get some exception? or any error?
- 07-20-2007, 04:35 AM #3
Member
- Join Date
- Jul 2007
- Posts
- 2
- Rep Power
- 0
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, 10:42 PM #4
Member
- Join Date
- Jul 2007
- Posts
- 43
- Rep Power
- 0
please paste the code, probably the problem is in it
- 11-05-2007, 01:42 PM #5
Member
- Join Date
- Nov 2007
- Posts
- 2
- Rep Power
- 0
- 01-02-2008, 01:55 PM #6
Member
- Join Date
- Dec 2007
- Posts
- 28
- Rep Power
- 0
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, 02:48 AM #7
Member
- Join Date
- Apr 2008
- Posts
- 28
- Rep Power
- 0
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, 11:18 AM #8
Have you constructed the query string correctly?
Java Code:"SELECT * FROM " + tablename + " WHERE " + tablename.fieldname + " = " + variablename;
Last edited by DonCash; 04-22-2008 at 11:21 AM.
Did this post help you? Please
me! :cool:
- 04-22-2008, 11:30 AM #9
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
- 04-22-2008, 12:03 PM #10
Member
- Join Date
- Apr 2008
- Posts
- 91
- Rep Power
- 0
Hei Eranga, You have pointed out the error.
- 04-22-2008, 12:54 PM #11
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
It's not Java at all pal. Don may put it by a mistake :)
- 04-22-2008, 01:15 PM #12
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
me! :cool:
- 04-23-2008, 03:24 AM #13
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
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. :)
Similar Threads
-
Select Count
By Apple2 in forum JavaServer Pages (JSP) and JSTLReplies: 1Last Post: 04-29-2008, 09:02 AM -
JDBC select problem
By abhiN in forum JDBCReplies: 0Last Post: 03-12-2008, 08:09 AM -
Select specific cell
By Echilon in forum New To JavaReplies: 1Last Post: 01-01-2008, 07:47 AM -
Internationalization: Select language from combo box
By alejandrgarcia in forum AWT / SwingReplies: 0Last Post: 08-11-2007, 10:26 AM -
How to select/highlight an entire row in JTextArea
By Valeriano in forum AWT / SwingReplies: 2Last Post: 05-28-2007, 11:20 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks