日期:2014-05-20  浏览次数:20803 次

JTable与数据库 问题
public void out(){
String sql = "select * from admin";
db.dbconn();
int i=0,j;
try{
rs = db.stmt.executeQuery(sql);
ResultSetMetaData mm = rs.getMetaData();
while(rs.next()){
for(j=0;j<mm.getColumnCount();j++){
jTable.setValueAt(rs.getObject(j),i,j);
}
i = i + 1;
}
rs.close();
}catch(SQLException e){e.printStackTrace();}
db.closedb();

}

java.sql.SQLException: [Microsoft][ODBC 驱动程序管理器] 无效的描述器索引 
at sun.jdbc.odbc.JdbcOdbc.createSQLException(Unknown Source) 
at sun.jdbc.odbc.JdbcOdbc.standardError(Unknown Source) 
at sun.jdbc.odbc.JdbcOdbc.SQLColAttributes(Unknown Source) 
at sun.jdbc.odbc.JdbcOdbcResultSet.getColAttribute(Unknown Source) 
at sun.jdbc.odbc.JdbcOdbcResultSet.getColumnType(Unknown Source) 
at sun.jdbc.odbc.JdbcOdbcResultSet.getObject(Unknown Source) 
at k.management.out(management.java:100) 
at k.management.initialize(management.java:37) 
at k.management.<init>(management.java:25) 
at k.tools$2.actionPerformed(tools.java:75) 
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) 

请问问题出在哪呢

------解决方案--------------------
jTable.setValueAt(rs.getObject(j),i,j); -> jTable.setValueAt(rs.getObject(j+1),i,j); // 数据是从1开始的,跟数组有点区别