我是新來的這個論壇,也是SQL的新手。3的索引超出範圍
我的下面的代碼有問題。
其拋出的SQLException
錯誤是the index 3 is out of range
我不知道有什麼問題就。
public static ArrayList<LotInfoVO> getLotInfoRecords3(String studName,String DoubleCheck, String lngstudid) throws ClassNotFoundException {
{
ArrayList <LotInfoVO> lotRecords4 = new ArrayList<LotInfoVO>();
try {
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
PreparedStatement stmt = getCon().prepareStatement("SELECT * FROM MesLib.tblSchoolRecordsr where strstudName = ? and strDoubleCheckCode = ? and (lngstudID NOT LIKE '-[^0-9]') ");
stmt.setString(1, studName);
stmt.setString(2, DoubleCheck);
stmt.setString(3, lngstudID);
ResultSet rs = stmt.executeQuery();
while(rs.next()) {
LotInfoVO voLotInfo3 = new LotInfoVO();
voLotInfo3.setStstudName(rs.getString("strstudName"));
voLotInfo3.setLngStudID(rs.getString("lngStudID"));
voLotInfo3.setLngStudSubID(rs.getString("lngStudSubID"));
voLotInfo3.setStrDoubleCheckCode(rs.getString("strDoubleCheckCode"));
voLotInfo3.setStrPackage(rs.getString("strCourse"));
voLotInfo3.setStrDimension(rs.getString("strSchool"));
voLotInfo3.setStrLead(rs.getString("strSubjects"));
//get values for other instance variables
lotRecords4.add(voLotInfo3);
}
} catch (SQLException e) {
e.printStackTrace();
} finally {
closeConnection();
}
return lotRecords4;
}
}
對不起,我的編碼我只是在城裏有一個新的程序員..
所以,請對我好感謝!
SQL代表「結構化查詢語言」。請告訴我們(更新標籤)你的DBMS是什麼? SQL Server?甲骨文?等等。 –
當您詢問有關異常情況時,請始終發佈異常的完整堆棧跟蹤。根據你對信息的改寫,我懷疑原因是你爲你的陳述設置了3個參數,儘管它只有2個''''。 –
您的查詢只有兩個'''佔位符,而不是三個。 – Berger