package bao;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class TestConnect {
/**
* @param args
* @throws IllegalAccessException
* @throws InstantiationException
*/
public static void main(String[] args) throws InstantiationException, IllegalAccessException {
// TODO Auto-generated method stub
try{
//加载驱动程序
// Class.forName("org.apache.derby.jdbc.clientDriver");
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver").newInstance();
//创建连接
//Connection conn=DriverManager.getConnection("jdbc:derby://localhost:1527/test;create=false");
String url="jdbc:odbc:Driver={MicroSoft Access Driver (*.mdb)};DBQ=F://test.mdb";
Connection conn = DriverManager.getConnection(url,"","");
String sql="select * from student";
Statement stmt=conn.createStatement();
ResultSet rs=stmt.executeQuery(sql);
while(rs.next()){
System.out.print(rs.getString(1)+"/t"+rs.getString(2)+"/t"+rs.getString(3)+"/r");
}
rs.close();
stmt.close();
conn.close();
}catch(SQLException e){
e.printStackTrace();
}catch(ClassNotFoundException e) {e.printStackTrace();}
}
}