• Post Reply Bookmark Topic Watch Topic
  • New Topic

sql statement problem

 
Rekha Pande
Ranch Hand
Posts: 145
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi all...

when we have to pass a string value to a sql stmt .. we usually write
(select * from atable where username = '"+username+"').. but supposing we have an int variable
int userid = 4;
int serialno=2;

how will i use this in the sql statement... if i use the below stmt it gives me an error...???
(select * from atable where userid = '"+userid+"' and serailno = '"+serialno+"')..

plz tell me how i can use numeric values in sql statements......plz

Thanxs...
 
Julian Kennedy
Ranch Hand
Posts: 823
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Rekha,

The reason you're getting an error is because the single quotes are used to delimit a string/varchar in SQL. Remove them and it'll work fine. A better solution, however, is to use a PreparedStatement instead of a plain old Statement. Check it out in the Javadoc, a book or one of Sun's JDBC tutorials.

Your other question about paging has been discussed recently on this site. I can't remember exactly where (JDBC?, HTML/JavaScript?, possibly this forum) but you might try searching a few forums.

Jules
 
Jeanne Boyarsky
author & internet detective
Sheriff
Posts: 36031
432
Eclipse IDE Java VI Editor
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65666
129
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moving to the JDBC forum.
 
Gravity is a harsh mistress. But this tiny ad is pretty easy to deal with:
the new thread boost feature: great for the advertiser and smooth for the coderanch user
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!