File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JDBC and the fly likes sql statement problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "sql statement problem" Watch "sql statement problem" New topic
Author

sql statement problem

Rekha Pande
Ranch Hand

Joined: Jan 29, 2004
Posts: 145
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

Joined: Aug 02, 2004
Posts: 823
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
internet detective
Marshal

Joined: May 26, 2003
Posts: 29237
    
139

The other thread Jules was alluding to.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60053
    
  65

Moving to the JDBC forum.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: sql statement problem
 
Similar Threads
Prepared Statement with wild card
The question about CLOB serialize? Thank you !!!
Replace JDBC calls with webservices
case sensitive sql statement for username and password
unable to forward using jsp:forward