Go Back   CodingForums.com > :: Server side development > Java and JSP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 12-28-2011, 08:04 AM   PM User | #1
sam71
New to the CF scene

 
Join Date: Dec 2011
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
sam71 is an unknown quantity at this point
SQL Error

I am new to Java and getting a run time error in sql statement in the java code.

Below is the test code. I want to select the row from CUSTOMER table where CUSTLOGINID = "abc"
Code:
String username = "abc";
String sqlText  = "select CustId, CustLoginId, CustPassword from javaDB.Customer where custLoginId = ";

stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery(sqlText + " '+username+' ");
Please advice what is wrong in above code.

Thanks
sam71 is offline   Reply With Quote
Old 12-28-2011, 01:22 PM   PM User | #2
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,635
Thanks: 4
Thanked 2,448 Times in 2,417 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
And what is the error you are receiving?

You may as well simplify this as well by making it a prepared statement. Prepared statements have many advantages over standard statements.

Code:
String username = "abc";
String sqlText  = "select CustId, CustLoginId, CustPassword from javaDB.Customer where custLoginId = ?";

PreparedStatement stmt = conn.prepareStatement(sqlText);
stmt.setString(1, username);
ResultSet rs = stmt.executeQuery();
Fou-Lu is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 02:51 PM.


Advertisement
Log in to turn off these ads.