java常用数据库的链接方法

阅读更多
MySQL:
StringDriver
= " com.mysql.jdbc.Driver " ; // 驱动程序
StringURL = " jdbc:mysql://localhost:3306/db_name " ; // 连接的URL,db_name为数据库名
StringUsername = " username " ; // 用户名
StringPassword = " password " ; // 密码
Class.forName(Driver). new Instance();
Connectioncon
= DriverManager.getConnection(URL,Username,Password);
MicrosoftSQLServer
2 .0驱动(3个jar的那个):
StringDriver
= " com.microsoft.jdbc.sqlserver.SQLServerDriver " ; // 连接SQL数据库的方法
StringURL = " jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=db_name " ; // db_name为数据库名
StringUsername = " username " ; // 用户名
StringPassword = " password " ; // 密码
Class.forName(Driver). new Instance(); // 加载数据可驱动
Connectioncon = DriverManager.getConnection(URL,UserName,Password); //
MicrosoftSQLServer 3 .0驱动(1个jar的那个): // 老紫竹完善
StringDriver = " com.microsoft.sqlserver.jdbc.SQLServerDriver " ; // 连接SQL数据库的方法
StringURL = " jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=db_name " ; // db_name为数据库名
StringUsername = " username " ; // 用户名
StringPassword = " password " ; // 密码
Class.forName(Driver). new Instance(); // 加载数据可驱动
Connectioncon = DriverManager.getConnection(URL,UserName,Password); //
Sysbase:
StringDriver
= " com.sybase.jdbc.SybDriver " ; // 驱动程序
StringURL = " jdbc:Sysbase://localhost:5007/db_name " ; // db_name为数据可名
StringUsername = " username " ; // 用户名
StringPassword = " password " ; // 密码
Class.forName(Driver).newInstance();
Connectioncon
= DriverManager.getConnection(URL,Username,Password);
Oracle(用thin模式):
StringDriver
= " oracle.jdbc.driver.OracleDriver " ; // 连接数据库的方法
StringURL = " jdbc:oracle:thin:@loaclhost:1521:orcl " ; // orcl为数据库的SID
StringUsername = " username " ; // 用户名
StringPassword = " password " ; // 密码
Class.forName(Driver).newInstance(); // 加载数据库驱动
Connectioncon = DriverManager.getConnection(URL,Username,Password);
PostgreSQL:
StringDriver
= " org.postgresql.Driver " ; // 连接数据库的方法
StringURL = " jdbc:postgresql://localhost/db_name " ; // db_name为数据可名
StringUsername = " username " ; // 用户名
StringPassword = " password " ; // 密码
Class.forName(Driver).newInstance();
Connectioncon
= DriverManager.getConnection(URL,Username,Password);
DB2:
StringDriver
= " com.ibm.db2.jdbc.app.DB2.Driver " ; // 连接具有DB2客户端的Provider实例
// StringDriver="com.ibm.db2.jdbc.net.DB2.Driver"; // 连接不具有DB2客户端的Provider实例
StringURL = " jdbc:db2://localhost:5000/db_name " ; // db_name为数据可名
StringUsername = " username " ; // 用户名
StringPassword = " password " ; // 密码
Class.forName(Driver).newInstance();
Connectioncon
= DriverManager.getConnection(URL,Username,Password);
Informix:
StringDriver
= " com.informix.jdbc.IfxDriver " ;
StringURL
= " jdbc:Informix-sqli://localhost:1533/db_name:INFORMIXSER=myserver " ; // db_name为数据可名
StringUsername = " username " ; // 用户名
StringPassword = " password " ; // 密码
Class.forName(Driver).newInstance();
Connectioncon
= DriverManager.getConnection(URL,Username,Password);
JDBC
- ODBC:
StringDriver
= " sun.jdbc.odbc.JdbcOdbcDriver " ;
StringURL
= " jdbc:odbc:dbsource " ; // dbsource为数据源名
StringUsername = " username " ; // 用户名
StringPassword = " password " ; // 密码
Class.forName(Driver).newInstance();
Connectioncon
= DriverManager.getConnection(URL,Username,Password);

你可能感兴趣的:(Java,JDBC,DB2,Oracle,Informix)