有人发现我的更新或插入查询有问题吗?我正在使用准备好的声明
public void insertOrUpdate(String customerNumber, Long CreditLimitAmount) 抛出 SQLException {
Connection connection2 = UBOCMSSQLConnectionUtill.getMSSqlConnection();
connection2.setAutoCommit(false);
PreparedStatement updatePreparedStatement = null;
PreparedStatement insertPreparedStatement = null;
try {
String updateQuery = "UPDATE CRLM2 SET BR=?, LIMITTYPE =?, LIMITMEMBER=?,"
+ "PRODUCT=?,PRODTYPE=?,MTYDATE=?,CCY=?,CREQLIMAMT=?,MRKTLIMAMT=?,EXPDATE=?,"
+ "PRODGROUPID=?,AMT1=?,AMT2=?,DATE1=?,DATE2=?,TEXT1=?,TEXT2=?,LIMITSEQ=?,"
+ "STARTDATE=?,UPDATECOUNTER=? WHERE LIMITMEMBER = ?";
String insertQuery = "insert into CRLM2(" + "BR," + "LIMITTYPE,"
+ "LIMITMEMBER," + "PRODUCT," + "PRODTYPE," + "MTYDATE,"
+ "CCY," + "CREQLIMAMT," + "MRKTLIMAMT," + "EXPDATE,"
+ "PRODGROUPID" + "AMT1," + "AMT2," + "DATE1," + "DATE2,"
+ "TEXT1," + "TEXT2," + "LIMITSEQ," + "STARTDATE,"
+ "UPDATECOUNTER) "
+ "values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
/**
* First try to update the row, but if that row does not exists,
* then insert it.
*/
updatePreparedStatement = connection2.prepareStatement(updateQuery);
updatePreparedStatement.setString(1, "01");
updatePreparedStatement.setString(2, "C");
updatePreparedStatement.setString(3, customerNumber);
updatePreparedStatement.setString(4, "FXD");
updatePreparedStatement.setString(5, "FX");
updatePreparedStatement.setString(6, "tbd");
updatePreparedStatement.setString(7, "USD");
updatePreparedStatement.setLong(8, creditLimitAmount);
updatePreparedStatement.setNull(9, java.sql.Types.NUMERIC);
updatePreparedStatement.setNull(10, java.sql.Types.DATE);
updatePreparedStatement.setNull(11, java.sql.Types.CHAR);
updatePreparedStatement.setNull(12, java.sql.Types.NUMERIC);
updatePreparedStatement.setNull(13, java.sql.Types.NUMERIC);
updatePreparedStatement.setNull(14, java.sql.Types.DATE);
updatePreparedStatement.setNull(15, java.sql.Types.DATE);
updatePreparedStatement.setNull(16, java.sql.Types.CHAR);
updatePreparedStatement.setNull(17, java.sql.Types.CHAR);
updatePreparedStatement.setNull(18, java.sql.Types.NUMERIC);
updatePreparedStatement.setNull(19, java.sql.Types.DATE);
updatePreparedStatement.setNull(20, java.sql.Types.NUMERIC);
int count = updatePreparedStatement.executeUpdate();
System.out.println("count value after updatePreparedStatement is "
+ count);
connection2.commit();
connection2.close();
updatePreparedStatement.close();
Connection connection3 = UBOCMSSQLConnectionUtill
.getMSSqlConnection();
insertPreparedStatement = connection3.prepareStatement(insertQuery);
connection3.setAutoCommit(false);
if (count == 0) {
insertPreparedStatement.setString(1, "01");
insertPreparedStatement.setString(2, "C");
insertPreparedStatement.setString(3, customerNumber);
insertPreparedStatement.setString(4, "FXD");
insertPreparedStatement.setString(5, "FX");
insertPreparedStatement.setString(6, "tbd");
insertPreparedStatement.setString(7, "USD");
insertPreparedStatement.setLong(8, creditLimitAmount);
insertPreparedStatement.setNull(9, java.sql.Types.NUMERIC);
insertPreparedStatement.setNull(10, java.sql.Types.DATE);
insertPreparedStatement.setNull(11, java.sql.Types.CHAR);
insertPreparedStatement.setNull(12, java.sql.Types.NUMERIC);
insertPreparedStatement.setNull(13, java.sql.Types.NUMERIC);
insertPreparedStatement.setNull(14, java.sql.Types.DATE);
insertPreparedStatement.setNull(15, java.sql.Types.DATE);
insertPreparedStatement.setNull(16, java.sql.Types.CHAR);
insertPreparedStatement.setNull(17, java.sql.Types.CHAR);
insertPreparedStatement.setNull(18, java.sql.Types.NUMERIC);
insertPreparedStatement.setNull(19, java.sql.Types.DATE);
insertPreparedStatement.setNull(20, java.sql.Types.NUMERIC);
insertPreparedStatement.executeUpdate();
connection3.commit();
}
} finally {
if (insertPreparedStatement != null) {
insertPreparedStatement.close();
}
}
}
}
找到并返回 db conn java.sql.SQLException:[Microsoft][SQLServer 2000 JDBC 驱动程序]参数绑定无效。 在 com.microsoft.jdbc.base.BaseExceptions.createException(来源未知) 在 com.microsoft.jdbc.base.BaseExceptions.getException(来源未知) 在 com.microsoft.jdbc.base.BasePreparedStatement.validateParameters(来源未知) 在 com.microsoft.jdbc.base.BasePreparedStatement.validateParameters(来源未知) 在 com.microsoft.jdbc.base.BasePreparedStatement.preImplExecute(来源未知) 在 com.microsoft.jdbc.base.BaseStatement.commonExecute(来源未知) 在 com.microsoft.jdbc.base.BaseStatement.executeUpdateInternal(来源未知) 在 com.microsoft.jdbc.base.BasePreparedStatement.executeUpdate(来源未知) 在 com.uboc.pdealcc.dao.PDealCCDao.insertOrUpdate(PDealCCDao.java:98) 在 com.uboc.pdealcc.dao.PDealCCDao.getCustomerId(PDealCCDao.java:37) 在 com.uboc.pdealcc.processor.COpxDeal.CheckQlim(COpxDeal.java:165) 在 com.uboc.pdealcc.listeners.TablePopupListener.actionPerformed(TablePopupListener.java:130) 在 javax.swing.AbstractButton.fireActionPerformed(来源未知) 在 javax.swing.AbstractButton$Handler.actionPerformed(来源未知)
public void insertOrUpdate(String customerNumber, Long creditLimitAmount)
throws SQLException {
Connection connection2 = UBOCMSSQLConnectionUtill.getMSSqlConnection();
connection2.setAutoCommit(false);
PreparedStatement updatePreparedStatement = null;
PreparedStatement insertPreparedStatement = null;
try {
String updateQuery = "UPDATE CRLM2 SET BR=?, LIMITTYPE =?, LIMITMEMBER=?,"
+ "PRODUCT=?,PRODTYPE=?,MTYDATE=?,CCY=?,CREQLIMAMT=?,MRKTLIMAMT=?,EXPDATE=?,"
+ "PRODGROUPID=?,AMT1=?,AMT2=?,DATE1=?,DATE2=?,TEXT1=?,TEXT2=?,LIMITSEQ=?,"
+ "STARTDATE=?,UPDATECOUNTER=? WHERE LIMITMEMBER = ?";
String insertQuery = "insert into CRLM2(" + "BR," + "LIMITTYPE,"
+ "LIMITMEMBER," + "PRODUCT," + "PRODTYPE," + "MTYDATE,"
+ "CCY," + "CREQLIMAMT," + "MRKTLIMAMT," + "EXPDATE,"
+ "PRODGROUPID" + "AMT1," + "AMT2," + "DATE1," + "DATE2,"
+ "TEXT1," + "TEXT2," + "LIMITSEQ," + "STARTDATE,"
+ "UPDATECOUNTER) "
+ "values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
/**
* First try to update the row, but if that row does not exists,
* then insert it.
*/
updatePreparedStatement = connection2.prepareStatement(updateQuery);
updatePreparedStatement.setString(1, "01");
updatePreparedStatement.setString(2, "C");
updatePreparedStatement.setString(3, customerNumber);
updatePreparedStatement.setString(4, "FXD");
updatePreparedStatement.setString(5, "FX");
updatePreparedStatement.setString(6, "tbd");
updatePreparedStatement.setString(7, "USD");
updatePreparedStatement.setLong(8, creditLimitAmount);
updatePreparedStatement.setNull(9, java.sql.Types.NUMERIC);
updatePreparedStatement.setNull(10, java.sql.Types.DATE);
updatePreparedStatement.setNull(11, java.sql.Types.CHAR);
updatePreparedStatement.setNull(12, java.sql.Types.NUMERIC);
updatePreparedStatement.setNull(13, java.sql.Types.NUMERIC);
updatePreparedStatement.setNull(14, java.sql.Types.DATE);
updatePreparedStatement.setNull(15, java.sql.Types.DATE);
updatePreparedStatement.setNull(16, java.sql.Types.CHAR);
updatePreparedStatement.setNull(17, java.sql.Types.CHAR);
updatePreparedStatement.setNull(18, java.sql.Types.NUMERIC);
updatePreparedStatement.setNull(19, java.sql.Types.DATE);
updatePreparedStatement.setNull(20, java.sql.Types.NUMERIC);
int count = updatePreparedStatement.executeUpdate();
System.out.println("count value after updatePreparedStatement is "
+ count);
connection2.commit();
connection2.close();
updatePreparedStatement.close();
Connection connection3 = UBOCMSSQLConnectionUtill
.getMSSqlConnection();
insertPreparedStatement = connection3.prepareStatement(insertQuery);
connection3.setAutoCommit(false);
if (count == 0) {
insertPreparedStatement.setString(1, "01");
insertPreparedStatement.setString(2, "C");
insertPreparedStatement.setString(3, customerNumber);
insertPreparedStatement.setString(4, "FXD");
insertPreparedStatement.setString(5, "FX");
insertPreparedStatement.setString(6, "tbd");
insertPreparedStatement.setString(7, "USD");
insertPreparedStatement.setLong(8, creditLimitAmount);
insertPreparedStatement.setNull(9, java.sql.Types.NUMERIC);
insertPreparedStatement.setNull(10, java.sql.Types.DATE);
insertPreparedStatement.setNull(11, java.sql.Types.CHAR);
insertPreparedStatement.setNull(12, java.sql.Types.NUMERIC);
insertPreparedStatement.setNull(13, java.sql.Types.NUMERIC);
insertPreparedStatement.setNull(14, java.sql.Types.DATE);
insertPreparedStatement.setNull(15, java.sql.Types.DATE);
insertPreparedStatement.setNull(16, java.sql.Types.CHAR);
insertPreparedStatement.setNull(17, java.sql.Types.CHAR);
insertPreparedStatement.setNull(18, java.sql.Types.NUMERIC);
insertPreparedStatement.setNull(19, java.sql.Types.DATE);
insertPreparedStatement.setNull(20, java.sql.Types.NUMERIC);
insertPreparedStatement.executeUpdate();
connection3.commit();
}
} finally {
if (insertPreparedStatement != null) {
insertPreparedStatement.close();
}
}
}
}
found and returning db conn
java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC]Invalid parameter binding(s).
at com.microsoft.jdbc.base.BaseExceptions.createException(Unknown Source)
at com.microsoft.jdbc.base.BaseExceptions.getException(Unknown Source)
at com.microsoft.jdbc.base.BasePreparedStatement.validateParameters(Unknown Source)
at com.microsoft.jdbc.base.BasePreparedStatement.validateParameters(Unknown Source)
at com.microsoft.jdbc.base.BasePreparedStatement.preImplExecute(Unknown Source)
at com.microsoft.jdbc.base.BaseStatement.commonExecute(Unknown Source)
at com.microsoft.jdbc.base.BaseStatement.executeUpdateInternal(Unknown Source)
at com.microsoft.jdbc.base.BasePreparedStatement.executeUpdate(Unknown Source)
at com.uboc.pdealcc.dao.PDealCCDao.insertOrUpdate(PDealCCDao.java:98)
at com.uboc.pdealcc.dao.PDealCCDao.getCustomerId(PDealCCDao.java:37)
at com.uboc.pdealcc.processor.COpxDeal.CheckQlim(COpxDeal.java:165)
at com.uboc.pdealcc.listeners.TablePopupListener.actionPerformed(TablePopupListener.java:130)
at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
更新查询中有 21 个参数,但您仅设置其中 20 个参数的值。
There are 21 parameters in the update query but you are only setting values for 20 of them.
文森特是对的。您的更新查询有 21 个参数,您的插入查询有 20 个参数。但是,在您的代码中,您仅为更新查询设置 20 个参数。
LIMITMEMBER 是参数号 3 和 21。
Vincent is right. Your update query has 21 params and your insert query has 20 params. However in your code you are only setting 20 params for your update query.
LIMITMEMBER is param number 3 and 21.