Last active
October 5, 2015 18:07
-
-
Save zxlooong/2850728 to your computer and use it in GitHub Desktop.
ConnectAccess.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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