我对下面方法中的 SQL 字符串查询感到困惑。它显示绝对正确,无论谁在 Oracle 数据库中创建了行,都会引发以下异常:ORA-0933:命令未正确结束。我尝试寻找解决方案,但没有结果。
出了什么问题?你能帮我吗?
预先感谢您,对于英语不好的地方深表歉意。
public void insertMemberAction() {
String query = "INSERT INTO MEMBERS VALUES(" + jMnoTxt.getText() + ", '" +
jLastnameTxt.getText() + "', '" + jFirstnameTxt.getText() + "', '" +
jAddressTxt.getText() + "', '" + jRegistrationDateTxt.getText() + "')";
java.sql.Statement insertStmt;
try {
insertStmt = DvdClubJFrame.con.createStatement();
insertStmt.executeUpdate(query);
insertStmt.close();
} catch (java.sql.SQLException e) {
javax.swing.JOptionPane.showMessageDialog(this, e.getMessage());
}
}
最佳答案
使用PreparedStatements,或者使用apache common的StringEscapeUtils
转义参数
关于Java SQLException - ORA-0933 : command not properly ended,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20128450/