-
jdbc problem!!! pls help
Well this is the code i m working on... the commented statement work perfectly.. but i want the prepared statement to work..
unfortunately prepared statement doesn't work..
what am i doing wrong?
once again! if i comment the prepared statement and uncomment the commented statement code fragments that does work..
public void register(String username,String firstName,String lastName,String password) throws SQLException{
String query = "insert into user(username, first_name, last_name, password) values(?, ?, ?, ?)";
// i tried this too.. String query = "insert into user values(?, ?, ?, ?)";
PreparedStatement pstmt = conn.prepareStatement(query);
pstmt.clearParameters();
pstmt.setString(1,username);
pstmt.setString(2,firstName);
pstmt.setString(3,lastName);
pstmt.setString(4,password);
pstmt.executeUpdate();
// the following works perfectly
/* Statement statement = conn.createStatement();
statement.executeUpdate("INSERT INTO user VALUES ( username,'mark','laws','mark123');") ;*/
}
-
well with preparedStatement you first have to declare the variables you are trying to set. for example you are setting pstmt.setString(1,username), first declare username as string then try again