【发布时间】:2017-03-11 07:08:23
【问题描述】:
公共类 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
}
我得到的异常: org.h2.jdbc.JdbcSQLException:SQL 语句中的语法错误“INSERT INTO REGISTRATIONTABLE (?[*],?,?,?,?,?)”;预期的“标识符”; SQL语句:insert intoregistrationtable(?,?,?,?,?,?) [42001-193]
请帮忙。提前致谢。
【问题讨论】:
-
插入语句的语法如下:h2database.com/html/grammar.html#insert。你的不尊重这种语法。