Java 未更新的表
编辑:这个问题已经解决了 我正在更新表上的数据。代码如下:Java 未更新的表,java,mysql,sql,jsp,jdbc,Java,Mysql,Sql,Jsp,Jdbc,编辑:这个问题已经解决了 我正在更新表上的数据。代码如下: @Override public void UpdateQnsAns(Exam exam, String subject) { try { String sql = "update table " + subject + "_tbl set question=?, option1=?, option2=?," + " option3=?, option4=?, answers=?
@Override
public void UpdateQnsAns(Exam exam, String subject) {
try {
String sql = "update table " + subject + "_tbl set question=?, option1=?, option2=?,"
+ " option3=?, option4=?, answers=? where id=?";
PreparedStatement pst = new DBConnection().getConnection().prepareStatement(sql);
pst.setString(1, exam.getQuestion());
pst.setString(2, exam.getOption1());
pst.setString(3, exam.getOption2());
pst.setString(4, exam.getOption3());
pst.setString(5, exam.getOption4());
pst.setString(6, exam.getCorrectOption());
pst.setInt(7, exam.getId());
pst.executeUpdate();
} catch (SQLException ex) {
Logger.getLogger(ExamDaoImpl.class.getName()).log(Level.SEVERE, null, ex);
}
}
在这里,我猜错误显示在glassfish服务器的pst.executeUpdate()
上,因为下面错误的最后一行(com.edu.daoImpl.ExamDaoImpl.UpdateQnsAns(ExamDaoImpl.java:120))将我链接到pst.executeUpdate行。错误如下所示:
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'table java_tbl set question='What is the default value of Short variable?', opti' at line 1
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:411)
at com.mysql.jdbc.Util.getInstance(Util.java:386)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1053)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4120)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4052)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2503)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2664)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2794)
at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:2155)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2458)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2375)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2359)
at com.edu.daoImpl.ExamDaoImpl.UpdateQnsAns(ExamDaoImpl.java:120)
at com.edu.defaultServlet.ExamServlet.processRequest(ExamServlet.java:221)
at com.edu.defaultServlet.ExamServlet.doPost(ExamServlet.java:257)
更新表中的行的语法是update tablename。。。不更新表格表格名称…我认为您应该从“更新表格…”中删除“表格”一词。谢谢!!我是一个没有正确检查语法的白痴!:) UPDATE tablename ... UPDATE TABLE tablename ...