我只是想在我的应用程序中使用更新,但我不能。在控制台中,这个 mysql 命令可以工作,但在这里不行。
好吧,我在我的程序中使用了这个:
conexao = poolMySQL.connect();
final String sql = "UPDATE professor SET codlocal = ? WHERE codprof = ?";
pstmt = conexao.prepareStatement(sql);
pstmt.setInt(1, local);
pstmt.setInt(2, id);
try {
pstmt.executeUpdate(sql);
} catch (SQLException ex) {
Logger.getLogger(ProfessorDAO.class.getName()).log(Level.SEVERE, null, ex);
}
只是提醒一下,codlocal 是来自另一个名为 Localidade 的表的外键。我看到了一些关于加入的例子,但我无法想象这对我来说如何工作。
我明白了:
Grave: null
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '? WHERE codprof = ?' at line 1
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:525)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:409)
at com.mysql.jdbc.Util.getInstance(Util.java:384)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1054)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3566)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3498)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1959)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2113)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2562)
at com.mysql.jdbc.StatementImpl.executeUpdate(StatementImpl.java:1664)
at com.mysql.jdbc.StatementImpl.executeUpdate(StatementImpl.java:1583)
at DAO.ProfessorDAO.atualizaLocalidade(ProfessorDAO.java:153)
at DAO.Main.main(Main.java:23)
那么,我能做什么呢?
您必须使用 pstmt.executeUpdate();代替 pstmt.executeUpdate(sql);
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)