Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Need Help in JDBC-Ms access

 
Pratap Reddy
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13974
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 + "'";
 
Pratap Reddy
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Consider Paul's rocket mass heater.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic