您的位置:首页 > 数据库

各种数据库连接

2014-01-28 13:23 344 查看

各种数据库连接:

 

public void Dbcon() throws InstantiationException, IllegalAccessException, ClassNotFoundException, SQLException {
//JDBC-ODBC
String Driver = "sun.jdbc.odbc.JdbcOdbcDriver";
String URL = "jdbc:odbc:dbsource"; //dbsource为数据源名

//Oracle(thin模式):
String Driver1 = "oracle.jdbc.driver.OracleDriver"; //连接数据库的方法
String URL1 = "jdbc:oracle:thin:@loaclhost:1521:orcl"; //orcl为数据库的SID

//MySQL:
String Driver2 = "com.mysql.jdbc.Driver"; //驱动程序
String URL2 = "jdbc:mysql://localhost:3306/db_name"; //连接的URL,db_name为数据库名

//DB2:
String Drive3r = "com.ibm.db2.jdbc.app.DB2.Driver"; //连接具有DB2客户端的Provider实例
//String Driver="com.ibm.db2.jdbc.net.DB2.Driver";    //连接不具有DB2客户端的Provider实例
String URL3 = "jdbc:db2://localhost:5000/db_name"; //db_name为数据库名

//Microsoft SQL Server:
String Driver4 = "com.microsoft.jdbc.sqlserver.SQLServerDriver"; //连接SQL数据库的方法
String URL4 = "jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=db_name";

//Sysbase:
String Driver5 = "com.sybase.jdbc.SybDriver"; //驱动程序
String URL5 = "jdbc:Sysbase://localhost:5007/db_name";

//PostgreSQL:
String Driver6 = "org.postgresql.Driver"; //连接数据库的方法
String URL6 = "jdbc:postgresql://localhost/db_name";

//Informix:
String Driver7 = "com.informix.jdbc.IfxDriver";
String URL7 = "jdbc:Informix-sqli://localhost:1533/db_name:INFORMIXSER=myserver";

String Username = "username"; //用户名
String Password = "password"; //密码
Class.forName(Driver).newInstance();
Connection con = DriverManager.getConnection(URL, Username, Password);
}

 

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: