就编程来讲,对于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();
}