자바 연결 access 데이터베이스

import java.sql.*; 
public class ConnectAccess { 
/** 
*       : 
* 1:     access  a1.mdb,   D:\ ; 
* 2:      a1.mdb      Table1; 
* 3: Table1    ,         ; 
* 4:         ,         。 
*/ 
public static void main(String args[]) throws Exception { 
ConnectAccess ca=new ConnectAccess(); 
ca.ConnectAccessFile(); 
ca.ConnectAccessDataSource(); 
} 
public void ConnectAccessFile() throws Exception 
{ 
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); 
/** 
*     access  。 
*/ 
String dbur1 = "jdbc:odbc:driver={Microsoft Access Driver (*.mdb)};DBQ=d:\\a1.mdb"; 
Connection conn = DriverManager.getConnection(dbur1, "username", "password"); 
Statement stmt = conn.createStatement(); 
ResultSet rs = stmt.executeQuery("select * from Table1"); 
while (rs.next()) { 
System.out.println(rs.getString(1)); 
} 
rs.close(); 
stmt.close(); 
conn.close(); 

좋은 웹페이지 즐겨찾기