• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

sql statement problem

 
Ranch Hand
Posts: 145
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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...
 
Ranch Hand
Posts: 823
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The other thread Jules was alluding to.
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Moving to the JDBC forum.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic