在java如何用Access建立一个数据库
2个回答
展开全部
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.*;
public class connODBC {
public static Statement stmt;
public static ResultSet rs;
String sql;
public static void main(String[] args) {
connODBC task=new connODBC();
task.ConnectionODBC();
}
public void ConnectionODBC() {
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
String url = "jdbc:odbc:driver={Microsoft Access Driver (*.mdb)};DBQ=table.mdb";
Connection con = DriverManager.getConnection(url);
System.out.println("数据源连接成功...");
stmt=con.createStatement();
} catch (SQLException e) {
System.out.println(e.getMessage());
} catch (Exception e) {
System.out.println(e.getMessage());
}
}
}
}
注意:table.mdb文件必须在.java文件所在目录,必须存在。
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.*;
public class connODBC {
public static Statement stmt;
public static ResultSet rs;
String sql;
public static void main(String[] args) {
connODBC task=new connODBC();
task.ConnectionODBC();
}
public void ConnectionODBC() {
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
String url = "jdbc:odbc:driver={Microsoft Access Driver (*.mdb)};DBQ=table.mdb";
Connection con = DriverManager.getConnection(url);
System.out.println("数据源连接成功...");
stmt=con.createStatement();
} catch (SQLException e) {
System.out.println(e.getMessage());
} catch (Exception e) {
System.out.println(e.getMessage());
}
}
}
}
注意:table.mdb文件必须在.java文件所在目录,必须存在。
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询