aspose file tools*
The moose likes JDBC and the fly likes Need  Help in JDBC-Ms access Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Need  Help in JDBC-Ms access" Watch "Need  Help in JDBC-Ms access" New topic
Author

Need Help in JDBC-Ms access

Pratap Reddy
Ranch Hand

Joined: Jan 05, 2001
Posts: 36
String s = "kpreddy";
String query = "SELECT UserId FROM Security WHERE UserId =" + s;
PreparedStatement stmt = dbconn.prepareStatement(query);
ResultSet rs = stmt.executeQuery();
When I run this queary I get too few parameters. Please tell me
how to pass a host variable to select queary.
Thanks In Advance.
Pratap
Thomas Paul
mister krabs
Ranch Hand

Joined: May 05, 2000
Posts: 13974
if you are building a SQL statement it has to be well formed. The result you will get will look like:
SELECT UserId FROM Security WHERE UserId =kpreddy
kpreddy has to be in quotes! You need to do something like:
String query = "SELECT UserId FROM Security WHERE UserId ='" + s + "'";

Associate Instructor - Hofstra University
Amazon Top 750 reviewer - Blog - Unresolved References - Book Review Blog
Pratap Reddy
Ranch Hand

Joined: Jan 05, 2001
Posts: 36
Hi Thomas Paul,
With you suggestion I changed accordingly but this different error message "Column not Found". But I tried using dynamic SQl as follows it is working fine.

Using the above method I am able to get my requirements.
But Thanks for Help.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Need Help in JDBC-Ms access