I want the Java method to pull a record from my Oracle 11g database, but I ran into some problems in not getting any returned records. If I hard code the value by dividing line 4 and commenting on lines 5 and 7, the result
will be populated with a record. An exception is not excluded. 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"); }
user1 source share