...

View Full Version : SQL Error



sam71
12-28-2011, 08:04 AM
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"


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

Fou-Lu
12-28-2011, 01:22 PM
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.



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();



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum