java 访问数据库出错,高手帮忙解决!
我用java写了访问数据库的代码,插入数据没有问题,可读取数据时发生异常.
部分代码如下:
public void selectByNo() throws
SQLException {
conn=getConnection();
pstmt=conn.prepareStatement( "select * from StudentInfo where StudentNo=? ",ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
pstmt.setString(1,studentNo);
rs=pstmt.executeQuery();
tempImageFiles=new ArrayList <File> ();
if (rs.next()) {
setStudentNo(rs.getString( "StudentNo "));
setName(rs.getString( "Name "));
setGender(rs.getString( "Gender "));
setBirth(rs.getString( "Birth "));
setAddress(rs.getString( "Address "));
setStudentClass(rs.getString( "Class "));
setProfession(rs.getString( "Profession "));
setInstitute(rs.getString( "Institute "));
setPeople(rs.getString( "People "));
setPoliticsBackground(rs.getString( "PoliticsBackground "));
setEntranceTime(rs.getString( "EntranceTime "));
setStudyExperience(rs.getString( "StudyExperience "));
setMemo(rs.getString( "Memo "));
InputStream in=rs.getBinaryStream( "Photo ");
byte[] b=new byte[1024];
int i=0;
try {
do {
tempPicFileName= "temp "+new Random(1000000).nextInt()+ ".jpg ";
tempPicFile=new File(tempPicFileName);
} while(tempPicFile.exists());
FileOutputStream fout=new FileOutputStream(tempPicFile);
tempImageFiles.add(tempPicFile);
while ((i=in.read(b))!=-1) {
fout.write(b);
}
setPhotoPath(tempPicFileName);
} catch(
IOException e) {
e.printStackTrace();
}
}
else {
throw new SQLException( "该学生不存在! ");
}
rs.close();
pstmt.close();
conn.close();
}
报如下错误:
[Microsoft][SQLServer 2000 Driver for JDBC]ResultSet can not re-read row data for column 3.
at com.microsoft.jdbc.base.BaseExceptions.createException(Unknown Source)
at com.microsoft.jdbc.base.BaseExceptions.getException(Unknown Source)
at com.microsoft.jdbc.base.BaseResultSet.validateColumnIndex(Unknown Source)
at com.microsoft.jdbc.base.BaseResultSet.getString(Unknown Source)
at com.microsoft.jdbc.base.BaseResultSet.getString(Unknown Source)
at backControl.Student.selectByNo(DBConnection.java:409)
at backControl.LeaveSchoolDialog$1.actionPerformed(ControlModule.java:1171)
at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)