Link to home
Start Free TrialLog in
Avatar of liltyga
liltyga

asked on

Reference variables in SQL SELECT Statement

The JSP newbie here again....

I'm passing form values to a page, and want to reference one of the variables in my SELECT statement - that is - instaed of using
ResultSet rs = stmt.executeQuery("SELECT * FROM TABLE_T WHERE  ACCT_NO = 123 ");

I want to use a variable for the account number instead of the actual number.  I can reference that number by using <%= request.getParameter("custn") %>, but that synatax won't work if I use it in the SELECT statement like so:

ResultSet rs = stmt.executeQuery("SELECT * FROM TABLE_T WHERE  ACCT_NO = request.getParameter("custn") ");

I know I'm doing something wrong, but what?

Thx again for the help - I don't know what I would do without this site!

lil
ASKER CERTIFIED SOLUTION
Avatar of pat5star
pat5star

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Karaa
Karaa

String custn= request.getParameter("custn");       
ResultSet rs = stmt.executeQuery("SELECT * FROM TABLE_T WHERE  ACCT_NO LIKE '"+ custn +"'");

It will work
Avatar of liltyga

ASKER

Thanks so much you guys! :)
SELECT * FROM TABLE_T  WHERE CURDATE LIKE  '2003-01-01%'
SELECT * FROM TABLE_T WHERE CURDATE LIKE  '01-01-2003%'
SELECT * FROM TABLE_T  WHERE CURDATE > '2003-01-01:00.00.00' AND CURDATE<= '2003-01-01:23:59:59'