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

发布于 2024-11-08 17:41:08 字数 5318 浏览 0 评论 0原文

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

救赎№ 2024-11-15 17:41:08

更新查询中有 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

There are 21 parameters in the update query but you are only setting values for 20 of them.


    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
翻身的咸鱼 2024-11-15 17:41:08

文森特是对的。您的更新查询有 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文