Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
Thread: SQL Error
12-28-2011, 09:04 AM #1
- Join Date
- Dec 2011
- Thanked 0 Times in 0 Posts
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+' ");
12-28-2011, 02:22 PM #2
- Join Date
- Sep 2002
- Saskatoon, Saskatchewan
- Thanked 2,668 Times in 2,637 Posts
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();