Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Aug 9th, 2012  |  syntax: None  |  size: 1.27 KB  |  hits: 11  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Syntax error in Prepared statement while inserting into db
  2. public boolean SignUp(String last_name, String first_name,String email, String password,String confirm_password,String phone){
  3.  
  4.  
  5.  
  6.         Connect connect = new Connect();
  7.         Connection conn = connect.Connection();
  8.  
  9.         java.sql.PreparedStatement preparedStatement = null;
  10.         //NULL is the column for auto increment
  11.         String insertQuery = "INSERT INTO users VALUES (NULL, ?, ?, ?, ?, ?, ?)";
  12.         preparedStatement = conn.prepareStatement(insertQuery);
  13.         preparedStatement.setString(1, last_name);
  14.         preparedStatement.setString(2, first_name);
  15.         preparedStatement.setString(3, email);
  16.         preparedStatement.setString(4, password);
  17.         preparedStatement.setString(5, confirm_password);
  18.         preparedStatement.setString(6, phone);
  19.  
  20.         int rs = preparedStatement.executeUpdate(insertQuery);
  21.  
  22.         conn.close();
  23.        
  24. com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '?, ?, ?, ?, ?, ?)' at line 1
  25.        
  26. String insertQuery = "INSERT INTO users"
  27. +  " (last_name, first_name, email, password, confirm_password, phone)"
  28. +  " VALUES(?,?,?,?,?,?)";