try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
} catch (ClassNotFoundException e){}
Connection Ex1 = DriverManager.getConnection("jdbc:odbc:book");
Statement Ex1Stmt = Ex1.createStatement();
ResultSet rs = Ex1Stmt.executeQuery("SELECT * FROM dl ");
ResultSetMetaData md = rs.getMetaData(); //获得元数据信息
int cols = md.getColumnCount(); //获得列数 int rows = 3; //获得行数
rs.last();
rows = rs.getRow(); String head[] = new String[cols]; //保存表头数据
String data[][] = new String[rows][cols]; //保存表体数据 for (int t = 0; i<cols; t++)
{
head[t]= md.getColumnName(t+1); //表头数据初始化
}
rs.beforeFirst(); //移动到第一行记录前面
int k=0;
while(rs.next())
{
for (int h = 0; h<cols; h++)
{
data[k][h]=rs.getString(h+1); //表体数据数组初始化
}
k++; }
DefaultTableModel dtm = new DefaultTableModel(data,head);
JTable table = new JTable(dtm);
table.setBounds(0,0,300,300);
con.add(table);帮忙看下哪里出问题了?我实在找不出了。错误提示是:
java.sql.SQLException: Result set type is TYPE_FORWARD_ONLY
at sun.jdbc.odbc.JdbcOdbcResultSet.last(Unknown Source)
at book.SystemManage.<init>(SystemManage.java:31)
at book.MainPanel.actionPerformed(MainPanel.java:33)
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.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)说什么未知数据源 什么意思?
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
} catch (ClassNotFoundException e){}
Connection Ex1 = DriverManager.getConnection("jdbc:odbc:book");
Statement Ex1Stmt = Ex1.createStatement();
ResultSet rs = Ex1Stmt.executeQuery("SELECT * FROM dl ");
ResultSetMetaData md = rs.getMetaData(); //获得元数据信息
int cols = md.getColumnCount(); //获得列数 int rows = 3; //获得行数
rs.last();
rows = rs.getRow(); String head[] = new String[cols]; //保存表头数据
String data[][] = new String[rows][cols]; //保存表体数据 for (int t = 0; i<cols; t++)
{
head[t]= md.getColumnName(t+1); //表头数据初始化
}
rs.beforeFirst(); //移动到第一行记录前面
int k=0;
while(rs.next())
{
for (int h = 0; h<cols; h++)
{
data[k][h]=rs.getString(h+1); //表体数据数组初始化
}
k++; }
DefaultTableModel dtm = new DefaultTableModel(data,head);
JTable table = new JTable(dtm);
table.setBounds(0,0,300,300);
con.add(table);帮忙看下哪里出问题了?我实在找不出了。错误提示是:
java.sql.SQLException: Result set type is TYPE_FORWARD_ONLY
at sun.jdbc.odbc.JdbcOdbcResultSet.last(Unknown Source)
at book.SystemManage.<init>(SystemManage.java:31)
at book.MainPanel.actionPerformed(MainPanel.java:33)
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.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)说什么未知数据源 什么意思?
你的结果集可能是forward_only的,这样执行beforeFirst()方法就会出错
java.sql.SQLException: Result set type is TYPE_FORWARD_ONLY
意思是你的结果集
1.[ ResultSet.TYPE_FORWARD_ONLY 该常量指示指针只能向前移动的 ResultSet 对象的类型。]
2.[ResultSet.TYPE_SCROLL_SENSITIVE 该常量指示可滚动并且通常受其他的更改影响的 ResultSet 对象的类型。]
3.[ResultSet.CONCUR_UPDATABLE 该常量指示可以更新的 ResultSet 对象的并发模式。]
在你的程序中
Statement Ex1Stmt = Ex1.createStatement();
这句话应该这麽写
Statement Ex1Stmt = Ex1.createStateme(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);个人感觉回答对了,大家看看吧
问题已经解决,就如楼上所说 应该用Statement Ex1Stmt = Ex1.createStateme(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
才可以返回一个可以滚动的结果集!