- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有两张 table 。我需要从第二个表中针对 col2 获取列表中的一些列值,并在循环中动态更新第一个表。
代码:
int ownerUpdateCount = 0;
PreparedStatement statement = null;
Connection connection = null;
try{
while(featuresIT.hasNext()){
String feature = (String) featuresIT.next();
String updateOwnerQuery = "UPDATE `regression_reports` "
+ "JOIN `feature_testbed_owner_mapping_628` ON (`regression_reports`.Feature='"
+ feature
+ "' AND `regression_reports`.Feature = `feature_testbed_owner_mapping_628`.feature_as_on_webpage) "
+ "SET `regression_reports`.Owner = `feature_testbed_owner_mapping_628`.owner";
//logger.debug("\n updateOwnerQuery : " + updateOwnerQuery);
connection = dataSource.getConnection();
connection.setAutoCommit(true);
statement = connection.prepareStatement(updateOwnerQuery);
//ownerUpdateCount +=
ownerUpdateCount = statement.executeUpdate();
System.out.println(feature + " ownerUpdateCount : " + ownerUpdateCount);
}
logger.debug("\n ownerUpdateCount : " + ownerUpdateCount);
} catch (SQLException e) {
e.printStackTrace();
} finally {
try { if(null!=statement)statement.close();} catch (SQLException e)
{e.printStackTrace();}
try { if(null!=connection)connection.close();} catch (SQLException e)
{e.printStackTrace();}
}
错误:
<小时/>java.sql.SQLException: Can not issue data manipulation statements with executeQuery(). at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1078) at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:989) at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:975) at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:920) at com.mysql.jdbc.StatementImpl.checkForDml(StatementImpl.java:499) at com.mysql.jdbc.StatementImpl.executeQuery(StatementImpl.java:1518) at org.apache.tomcat.dbcp.dbcp.DelegatingStatement.executeQuery(DelegatingStatement.java:208) at org.apache.tomcat.dbcp.dbcp.DelegatingStatement.executeQuery(DelegatingStatement.java:208) at com.n7k.regression.RegressionDAO.updateRegReportsDB(RegressionDAO.java:71) at com.n7k.regression.RegressionServlet.doPost(RegressionServlet.java:63)
此错误仅发生在循环的第一次迭代中。任何调试其发生原因的建议。
String updateFeaturesQuery = "INSERT INTO `regression_reports` "
+ "(Feature, `Report`, `P`, `F`, `Remarks`) VALUES ('"
+ feature + "','" + report + "'," + pass + "," + fail
+ ") " + "ON DUPLICATE KEY UPDATE `Report` = '"
+ report + "', `P` = " + pass + ", `F`= " + fail
+ ", `Remarks` = " + remarks + ";";
connection = dataSource.getConnection();
statement = connection.prepareStatement(updateFeaturesQuery);
Line#73
featureUpdateCount = statement.executeUpdate(updateFeaturesQuery);
错误:
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 '' at line 1 at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27) at java.lang.reflect.Constructor.newInstance(Constructor.java:513) 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:1054) at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4190) at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4122) at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2570) at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2731) at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2812) at com.mysql.jdbc.StatementImpl.executeUpdate(StatementImpl.java:1811) at com.mysql.jdbc.StatementImpl.executeUpdate(StatementImpl.java:1725) at org.apache.tomcat.dbcp.dbcp.DelegatingStatement.executeUpdate(DelegatingStatement.java:228) at org.apache.tomcat.dbcp.dbcp.DelegatingStatement.executeUpdate(DelegatingStatement.java:228) at com.n7k.regression.RegressionDAO.updateRegReportsDB(RegressionDAO.java:73)
上面的执行给出了这个错误。手动执行相同的查询不会引发任何错误。
最佳答案
这里完全缺少您的备注
专栏,
// No `Remarks` even though you included it in the list. `F`, `Remarks`)
"," + fail /* + Remarks! */ + ") " + "ON DUPLICATE KEY UPDATE `Report` = '"
您的列备注
此处未转义,
+ ", `Remarks` = '" + remarks + "';";
但是您应该使用bind parameters或String StringEscapeUtils#escapeSql(String)因为您的代码容易受到 sql injection 的攻击.
关于java - JDBC、MySQL -PreparedStatementexecuteUpdate 出现 DML 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22522964/
我正在使用 Oracle 数据库,一段时间后我收到以下异常: java.sql.SQLException: ORA-01000: maximum open cursors exceeded 我分析了我
我使用 spring jdbctemplate 更新一些行,但是我收到了此日志消息。两个完全相同的 sql 返回不同的受影响行。第二个更新操作不可能返回 0 个受影响的行。我只是无法弄清楚。 2015
try{ Connection conn = getConnection(); String strUpdateQuery = "update payment_table set C
我有两张 table 。我需要从第二个表中针对 col2 获取列表中的一些列值,并在循环中动态更新第一个表。 代码: int ownerUpdateCount = 0; PreparedSta
我是一名优秀的程序员,十分优秀!