0

public class RegisterDao {

private static final String DB_DRIVER = "org.h2.Driver";
private static final String DB_CONNECTION = "jdbc:h2:~/test";
private static final String DB_USER = "admin";
private static final String DB_PASSWORD = "admin";

Connection dbConnection = null;
PreparedStatement pstmt = null;
public void forRegister(String name,int age,String address,String password,String email,String uuid){
    try {
        Class.forName(DB_DRIVER);
        System.out.println("Connecting to a selected database...");
    } catch (ClassNotFoundException e) {
        System.out.println(e.getMessage());
    }
    try {
        dbConnection = DriverManager.getConnection(DB_CONNECTION, DB_USER,
                DB_PASSWORD);
    System.out.println("Connected database successfully...");
    //Statement stat = dbConnection.createStatement();
    //ResultSet rs;
    if (dbConnection != null){
        System.out.println("starting entering data");
        pstmt=dbConnection.prepareStatement("insert into registrationtable (?,?,?,?,?,?)");

        pstmt.setString(1, name);
        pstmt.setInt(2, age);
        pstmt.setString(3, address);
        pstmt.setString(4, password);
        pstmt.setString(5, email);
        pstmt.setString(6, uuid);

        pstmt.executeUpdate();
        System.out.println("details are added");
    }
    } catch (SQLException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }  finally{
        //finally block used to close resources
        try{
           if(dbConnection!=null)
               dbConnection.close();
        }catch(SQLException se){
           se.printStackTrace();
        }//end finally try
     }//end try

}

Exception that I am getting : org.h2.jdbc.JdbcSQLException: Syntax error in SQL statement "INSERT INTO REGISTRATIONTABLE (?[*],?,?,?,?,?) "; expected "identifier"; SQL statement: insert into registrationtable (?,?,?,?,?,?) [42001-193]

Please help.Thanks in advance.

1

1 Answer 1

3

Try this sql:

 insert into registrationtable (name, age, address, password, email, uuid) values (?, ?, ?, ?, ?, ?)"

where name, age, address, password, email, uuid are the table field names, so probably you will have to rename them to fit your table schema.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.