Skip to content

Instantly share code, notes, and snippets.

@zxlooong
Last active October 5, 2015 18:07
Show Gist options
  • Save zxlooong/2850728 to your computer and use it in GitHub Desktop.
Save zxlooong/2850728 to your computer and use it in GitHub Desktop.
ConnectAccess.java
import java.sql.*;
class ConnectAccess{
String connStr;
public ConnectAccess(String accessDB_DSN_Name){
//accessDB_DSN_Nameabc为自己创建的系统DSN数据源名,对应一个Access数据库.
//String link="jdbc:odbc:driver={Microsoft Access Driver(*.mdb)};DBQ=H:\\summer\\javaxml\\db.mdb";
connStr = "jdbc:odbc:"+accessDB_DSN_Name;
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection(connStr,"","");
Statement statement=con.createStatement();
ResultSet rs=statement.executeQuery("select * from student");
while(rs.next()){
System.out.println(rs.getString(1)+" "+rs.getString(2) + " " + rs.getString(3));
}
rs.close();
statement.close();
con.close();
}catch(Exception e){
e.printStackTrace();
}
}
public static void main(String[] args){
ConnectAccess access = new ConnectAccess("abc");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment