java连接access数据库
import java.sql.*;
public class lin1{
public static void main(String args[]) throws Exception{
Class.forName( "sun.jdbc.odbc.JdbcOdbcDriver ");
String dburl = "jdbc:odbc:driver={Microsoft Access Driver (*.mdb)};DBQ=data/test.mdb ";//此为NO-DSN方式
//String dburl = "jdbc:odbc:test ";
Connection conn=DriverManager.getConnection(dburl);
Statement stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
//Statement stmt=conn.createStatement();
ResultSet rs=stmt.executeQuery( "select * from test ");
//System.out.println(rs.getString( "department "));
System.out.println(rs.getString(2));
rs.close();
stmt.close();
conn.close();
}
}
怎么结果老是说 无效的游标状态
请指教!
------解决方案--------------------在ResultSet rs = .....下加入 while(rs.next != null){ System.out.println(rs.getString( "department ")); .......} 因为从数据库查询出数据 游标指向是要查询纪录的上一级.....