当前位置: 技术问答>java相关
Java 数据库解决方案汇总。No ODBC 欢迎参与!!!进者有分
来源: 互联网 发布时间:2015-05-05
本文导语: 我提供MS 的Access解决方案: public DataBase(){ try{ Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); url = "jdbc:odbc:;DRIVER=Microsoft Access Driver (*.mdb);DBQ=t.mdb"; connection = DriverManager.getConnection(url, "", ""); ...
我提供MS 的Access解决方案:
public DataBase(){
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
url = "jdbc:odbc:;DRIVER=Microsoft Access Driver (*.mdb);DBQ=t.mdb";
connection = DriverManager.getConnection(url, "", "");
}
catch(Exception e){ e.printStackTrace(); }
}
public DataBase(){
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
url = "jdbc:odbc:;DRIVER=Microsoft Access Driver (*.mdb);DBQ=t.mdb";
connection = DriverManager.getConnection(url, "", "");
}
catch(Exception e){ e.printStackTrace(); }
}
|
我的Oracle
public DataBase(){
try{
DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
dbConnect = DriverManager.getConnection("jdbc:oracle:thin:@fish:1521:fish","","");
}
catch(Exception e){ e.printStackTrace(); }
}
public DataBase(){
try{
DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
dbConnect = DriverManager.getConnection("jdbc:oracle:thin:@fish:1521:fish","","");
}
catch(Exception e){ e.printStackTrace(); }
}
|
我用过
postgres
mysql 。
try{
//Class.forName ("org.gjt.mm.mysql.Driver");
Class.forName("org.postgresql.Driver");
// Connect to the database
//String url = "jdbc:mysql://" + host + ":" + port + "/" + sid;
String url = "jdbc:postgresql://" + host + ":" + port + "/" + sid;
Connection con = DriverManager.getConnection(url,user,password);
} catch (Exception e){
e.printStackTrace();
}
postgres
mysql 。
try{
//Class.forName ("org.gjt.mm.mysql.Driver");
Class.forName("org.postgresql.Driver");
// Connect to the database
//String url = "jdbc:mysql://" + host + ":" + port + "/" + sid;
String url = "jdbc:postgresql://" + host + ":" + port + "/" + sid;
Connection con = DriverManager.getConnection(url,user,password);
} catch (Exception e){
e.printStackTrace();
}