公共無效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(來源不明)
我只看到20 PARAMS – aditya86c 2011-05-20 00:00:13
@ aditya86c我換成你的?用數字顯示您實際擁有的參數數量。 – 2011-05-20 00:02:37
但我仍然看到這個錯誤[Microsoft] [SQLServer 2000 Driver for JDBC]對象已關閉。 – aditya86c 2011-05-20 00:11:50