当前位置: 代码迷 >> Eclipse >> JDBC报错,列名无效,该如何处理
  详细解决方案

JDBC报错,列名无效,该如何处理

热度:114   发布时间:2016-04-23 14:00:58.0
JDBC报错,,列名无效,
在SQLserver2005数据库可以查询得到结果,但是JDBC报错,,列名无效,崩溃了。看了好多朋友的帖子,都是说sql语句有误,可明明是对的啊,难道是rs哪里有问题吗。。求求大家给指点指点。。
public Vector<Object> getGradeinfo(String cname)
  {
Vector<Object> GradeData=new Vector<Object>();  
try

String sql="select Student.snum,Student.sname,Student.scname,Sgrade.gr_exam,Sgrade.gr_moral from Student,Sgrade" +
" where Student.snum=Sgrade.snum";
 
if(!cname.equals(""))
sql+=" and scname='"+cname+"'";
st5=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
rs5=st5.executeQuery(sql);
while(rs5.next())
{
Vector<Object> singleRow=new Vector<Object>();
for(int i=1;i<=rs5.getMetaData().getColumnCount();i++)
singleRow.add(rs5.getObject(i));
GradeData.addElement(singleRow);
}

}
catch(Exception e)
{e.printStackTrace();}
return GradeData;
  }
  public boolean updateGrade(int jt_row,DefaultTableModel dtm)
  {
boolean flag=false;
try{
rs5.absolute(jt_row+1);
for(int i=1;i<=rs5.getMetaData().getColumnCount();i++)
rs5.updateObject(i, dtm.getValueAt(jt_row, i-1));
rs5.updateRow();
flag=true;
}
catch(Exception e)
{e.printStackTrace();}
return flag;
}
 
}





com.microsoft.sqlserver.jdbc.SQLServerException: 列名 'gr_exam' 无效。
at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDatabaseError(SQLServerException.java:197)
at com.microsoft.sqlserver.jdbc.TDSTokenHandler.onEOF(tdsparser.java:246)
at com.microsoft.sqlserver.jdbc.TDSParser.parse(tdsparser.java:83)
at com.microsoft.sqlserver.jdbc.TDSParser.parse(tdsparser.java:39)
at com.microsoft.sqlserver.jdbc.SQLServerResultSet.doUpdateRowRPC(SQLServerResultSet.java:4049)
at com.microsoft.sqlserver.jdbc.SQLServerResultSet.access$200(SQLServerResultSet.java:16)
at com.microsoft.sqlserver.jdbc.SQLServerResultSet$1UpdateRowRPC.doExecute(SQLServerResultSet.java:3983)
at com.microsoft.sqlserver.jdbc.TDSCommand.execute(IOBuffer.java:4575)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.executeCommand(SQLServerConnection.java:1400)
at com.microsoft.sqlserver.jdbc.SQLServerStatement.executeCommand(SQLServerStatement.java:179)
at com.microsoft.sqlserver.jdbc.SQLServerResultSet.updateRow(SQLServerResultSet.java:4019)
at stuMngSys.DBoperate.updateGrade(DBoperate.java:338)
at stuMngSys.GradeMng$3.actionPerformed(GradeMng.java:56)
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)
  相关解决方案