我对此方法有疑问:
public void insertIntoQueue(DTOQueue dtoQueue) {
DbConnection dbConnection = new DbConnection();
Connection conn;
try {
conn = dbConnection.coneccion();
String sql = " INSERT INTO PURE_ENC_QUEUE (queueId,queueName) values(?,?);";
//creating PreparedStatement object to execute query
PreparedStatement preStatement = conn.prepareStatement(sql);
preStatement.setString(1, dtoQueue.getQueueId());
preStatement.setString(2, dtoQueue.getQueueName());
int result = preStatement.executeUpdate();
DbConnection.closeConnection(conn);
if(result > 0) {
System.out.println("Insertado");
} else {
System.out.println("No insertado");
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (InstantiationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalAccessException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println("done");
}
当我运行它时,抛出异常
java.sql.SQLException:ORA-00933:SQL命令未正确结束
对这个问题有什么想法吗?谢谢!
最佳答案
您需要在查询字符串的末尾删除分号,即:
String sql = "INSERT INTO PURE_ENC_QUEUE (queueId,queueName) values(?,?)";
同样,重构代码以使用the try-with-resources statement是个好主意。