首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > J2SE开发 >

java 访问数据库出错,高手帮忙解决!该如何解决

2012-01-31 
java 访问数据库出错,高手帮忙解决!我用java写了访问数据库的代码,插入数据没有问题,可读取数据时发生异常

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)


at   java.awt.Component.processMouseEvent(Unknown   Source)
at   javax.swing.JComponent.processMouseEvent(Unknown   Source)
at   java.awt.Component.processEvent(Unknown   Source)
at   java.awt.Container.processEvent(Unknown   Source)
at   java.awt.Component.dispatchEventImpl(Unknown   Source)
at   java.awt.Container.dispatchEventImpl(Unknown   Source)
at   java.awt.Component.dispatchEvent(Unknown   Source)
at   java.awt.LightweightDispatcher.retargetMouseEvent(Unknown   Source)
at   java.awt.LightweightDispatcher.processMouseEvent(Unknown   Source)
at   java.awt.LightweightDispatcher.dispatchEvent(Unknown   Source)
at   java.awt.Container.dispatchEventImpl(Unknown   Source)
at   java.awt.Window.dispatchEventImpl(Unknown   Source)
at   java.awt.Component.dispatchEvent(Unknown   Source)
at   java.awt.EventQueue.dispatchEvent(Unknown   Source)
at   java.awt.EventDispatchThread.pumpOneEventForHierarchy(Unknown   Source)
at   java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown   Source)
at   java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown   Source)
at   java.awt.Dialog$1.run(Unknown   Source)
at   java.awt.Dialog$2.run(Unknown   Source)
at   java.security.AccessController.doPrivileged(Native   Method)
at   java.awt.Dialog.show(Unknown   Source)
at   java.awt.Component.show(Unknown   Source)
at   java.awt.Component.setVisible(Unknown   Source)
at   backControl.ControlModuleFrame$5.valueChanged(ControlModule.java:160)
at   javax.swing.JTree.fireValueChanged(Unknown   Source)
at   javax.swing.JTree$TreeSelectionRedirector.valueChanged(Unknown   Source)
at   javax.swing.tree.DefaultTreeSelectionModel.fireValueChanged(Unknown   Source)
at   javax.swing.tree.DefaultTreeSelectionModel.notifyPathChange(Unknown   Source)
at   javax.swing.tree.DefaultTreeSelectionModel.setSelectionPaths(Unknown   Source)
at   javax.swing.tree.DefaultTreeSelectionModel.setSelectionPath(Unknown   Source)
at   javax.swing.JTree.setSelectionPath(Unknown   Source)
at   javax.swing.plaf.basic.BasicTreeUI.selectPathForEvent(Unknown   Source)
at   javax.swing.plaf.basic.BasicTreeUI$Handler.handleSelectionImpl(Unknown   Source)
at   javax.swing.plaf.basic.BasicTreeUI$Handler.handleSelection(Unknown   Source)
at   javax.swing.plaf.basic.BasicTreeUI$Handler.mousePressed(Unknown   Source)
at   java.awt.AWTEventMulticaster.mousePressed(Unknown   Source)
at   java.awt.Component.processMouseEvent(Unknown   Source)
at   javax.swing.JComponent.processMouseEvent(Unknown   Source)
at   java.awt.Component.processEvent(Unknown   Source)
at   java.awt.Container.processEvent(Unknown   Source)
at   java.awt.Component.dispatchEventImpl(Unknown   Source)
at   java.awt.Container.dispatchEventImpl(Unknown   Source)
at   java.awt.Component.dispatchEvent(Unknown   Source)
at   java.awt.LightweightDispatcher.retargetMouseEvent(Unknown   Source)
at   java.awt.LightweightDispatcher.processMouseEvent(Unknown   Source)
at   java.awt.LightweightDispatcher.dispatchEvent(Unknown   Source)
at   java.awt.Container.dispatchEventImpl(Unknown   Source)
at   java.awt.Window.dispatchEventImpl(Unknown   Source)
at   java.awt.Component.dispatchEvent(Unknown   Source)
at   java.awt.EventQueue.dispatchEvent(Unknown   Source)


at   java.awt.EventDispatchThread.pumpOneEventForHierarchy(Unknown   Source)
at   java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown   Source)
at   java.awt.EventDispatchThread.pumpEvents(Unknown   Source)
at   java.awt.EventDispatchThread.pumpEvents(Unknown   Source)
at   java.awt.EventDispatchThread.run(Unknown   Source)


[解决办法]
看着晕

[解决办法]
可能和你数据库里的对应列的数据类型有关!
[解决办法]
DBConnection.java:409行是哪里?
[解决办法]
可能是preparedStatement()中的参数设置有错误吧!...

热点排行