就編程來講,對於sql server,微軟提供了專門的jdbc驅動程序,也就是大家平常用的那三個jar文件。但access的編程可沒那麼豪華,現在可用的編程方法,只是提供一個jdbc-odbc橋接器進行連接,效率就不用說了哦。
大概過程也略略羅嗦一下:
1,創建制定數據庫的URL:同時配置access數據源
如: String url = "jdbc:odbc:Oblog";
2,加載驅動程序
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
3,創建連接
Connection conn = DriverManager.getConnection(url, "user", "pwd");
4,創建sql語句對象
Statement stmt = conn.createStatement();
5,執行sql語句
stmt.execute(strSql.toString());
干脆貼個例子:
//Select.java
import java.sql.*;
class Select{
public static void main(){
try{
String url = "jdbc:odbc:wombat";
Connection conn = DriverManager.getConnection(url,"user","pwd");
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery("SELECT * FROM Table1");
System.out.println("Got ResultSet Now");
rs.beforeFirst();
while(rs.next()){
System.out.println(rs.getString(1));
}
stmt.close();
conn.close();
}
catch(Exception ex){
ex.printStackTrace();
}