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

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

2012-01-21 
JDBC报错,,列名无效,在SQLserver2005数据库可以查询得到结果,但是JDBC报错,,列名无效,崩溃了。看了好多朋友

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)


at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(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)[/color][/color][/color]

[解决办法]
com.microsoft.sqlserver.jdbc.SQLServerException: 列名 'gr_exam' 无效。
是不是与数据库的列明不一致啊,
诊断sql是否异常很简单,你直接在
sql+=" and scname='"+cname+"'";之后
System.out.println(sql);
把控制台上的sql语句拷贝到sqlserver的客户端执行下看看能否正确执行就知道了。。。
[解决办法]
那在数据库中添加一个字段咯!
[解决办法]
看看是不是列名写错了
[解决办法]
你的sql语句拿到别的地方能执行么,譬如直接执行
[解决办法]
String sql="select Student.snum,Student.sname,Student.scname,Sgrade.gr_exam,Sgrade.gr_moral from Student inner join Sgrade where Student.snum=Sgrade.snum"

热点排行