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
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
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 30947
    
158

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: 61654
    
  67

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