2011-05-19 52 views
2

公共無效insertOrUpdate(字符串customerNumber之,龍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(); 
    } 
} 

} 

}

發現並返回康涅狄格州分貝值java.sql.SQLException :[微軟] [SQLServer的2000 Driver for JDBC]無效的參數綁定。 (未知源) 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源) 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) 在javax.swing.AbstractButton.fireActionPerformed(來源不明) 在javax.swing.AbstractButton中的$ Handler.actionPerformed(來源不明)

回答

1

有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 
+1

我只看到20 PARAMS – aditya86c 2011-05-20 00:00:13

+0

@ aditya86c我換成你的?用數字顯示您實際擁有的參數數量。 – 2011-05-20 00:02:37

+0

但我仍然看到這個錯誤[Microsoft] [SQLServer 2000 Driver for JDBC]對象已關閉。 – aditya86c 2011-05-20 00:11:50

0

文森特是正確的。你的更新查詢有21個參數,你的插入查詢有20個參數。但是,在你的代碼中,你只能爲你的更新查詢設置20個參數。

LIMITMEMBER是參數號碼3和21

+0

是否有人看到我的插入語句錯誤,特別是在BR – aditya86c 2011-05-20 01:16:59

+0

我得到這個java.sql.SQLException:[微軟] [JDBC的SQLServer 2000驅動程序] [SQLServer]錯誤的'BR'附近的語法。 – aditya86c 2011-05-20 01:17:20

相關問題