gpt4 book ai didi

java - 有人看到我的更新或插入查询有问题吗?我正在使用准备好的声明

转载 作者:行者123 更新时间:2023-11-30 11:53:50 26 4
gpt4 key购买 nike

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 connjava.sql.SQLException:[Microsoft][JDBC 的 SQLServer 2000 驱动程序]无效参数绑定(bind)。 在 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(未知来源)

最佳答案

更新查询中有 21 个参数,但您只设置了其中 20 个的值。


    UPDATE CRLM2 SET BR=1, LIMITTYPE =2, LIMITMEMBER=3,"
+ "PRODUCT=4,PRODTYPE=5,MTYDATE=6,CCY=7,CREQLIMAMT=8,MRKTLIMAMT=9,EXPDATE=10,"
+ "PRODGROUPID=11,AMT1=12,AMT2=13,DATE1=14,DATE2=15,TEXT1=16,TEXT2=17,LIMITSEQ=18,"
+ "STARTDATE=19,UPDATECOUNTER=20 WHERE LIMITMEMBER = 21

关于java - 有人看到我的更新或插入查询有问题吗?我正在使用准备好的声明,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6066065/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com