Prepared Statement Parameter Problems
I want a Java method to pull a record from my Oracle 11g database, but I'm
running into some trouble in that I am not getting any records returned.
If I hard-code a value by uncommenting line 4 and commenting lines 5 & 7,
result will be populated with a record. No exceptions are caught. What am
I missing?
conn = DriverManager.getConnection(url,props);
String sql = "select col1, col2, col3"
+ " from table1"
// + " where user_id = 'user123'"; // line 4
+ " where user_id = ?"; // line 5
PreparedStatement preStatement = conn.prepareStatement(sql);
preStatement.setString(1, "user123"); // line 7
ResultSet result = preStatement.executeQuery();
while(result.next()) {
System.out.println("works");
}
No comments:
Post a Comment