JDBC Connect various database mode quick checksheet

xiaoxiao2021-03-06  41

Below, various databases use the JDBC connection, can be used as a manual.

1, Oracle8 / 8i / 9i database (Thin mode)

Class.Forname ("Oracle.jdbc.driver.OracleDriver"). NewInstance (); String Url = "JDBC: Oracle: Thin: @localhost: 1521: ORCL"; // ORCL is the sid string user = "test" String password = "test"; connection conn = drivermanager.getConnection (URL, User, Password);

2, DB2 database

Class.Forname ("com.ibm.db2.jdbc.app.db2driver") .newinstance (); string url = "jdbc: db2: // localhost: 5000 / sample"; // Sample for your database name String User = "Admin"; string password = ""; connection conn = drivermanager.getConnection (URL, User, Password);

3, SQL Server7.0 / 2000 database

Class.Forname ("com.microsoft.jdbc.sqlser.sqlserverdriver). NewInstance (); string url =" JDBC: Microsoft: SQLServer: // localhost: 1433; databasename = mydb "; // mydb is database string user = "sa"; string password = ""; connection conn = drivermanager.getConnection (URL, User, Password);

4, Sybase database

Class.Forname ("com.sybase.jdbc.sybdriver). Newinstance (); string url =" jdbc: sybase: tds: localhost: 5007 / mydb "; // mydb for your database name Properties Sysprops = System.getProperties (); Sysprops.put ("user", "userid"); sysprops.put ("password", "user_password"); connection conn = drivermanager.getConnection (URL, Sysprops);

5, Informix database

Class.forName ( "com.informix.jdbc.IfxDriver") newInstance (); String url = "jdbc:. Informix-sqli: //123.45.67.89: 1533 / myDB: INFORMIXSERVER = myserver; user = testuser; password = testpassword "; // mydb is the database name Connection Conn = DriverManager.getConnection (URL);

6, MySQL database

Class.forName ( "org.gjt.mm.mysql.Driver") newInstance (); String url =. "Jdbc:? Mysql: // localhost / myDB user = soft & password = soft1234 & useUnicode = true & characterEncoding = 8859_1" // myDB database Name Connection Conn = DriverManager.getConnection (URL); 7, PostgreSQL Database

Class.Forname ("org.postgreSql.driver). NewInstance (); string url =" jdbc: postgreSQL: // localhost / mydb "// mydb is the database name string user =" myuser "; string password =" mypassword " Connection conn = drivermanager.getConnection (URL, User, Password);

8, Access database straight with ODBC

Class.Forname ("sun.jdbc.odbc.jdbcodbcdriver"); string url = "JDBC: ODBC: driver = {Microsoft Access Driver (* .mdb)}; dbq =" Application.getRealPath ("/ Data / ReportDemo. MDB "); connection conn = drivermanager.getConnection (URL,", "" "; statement stmtnew = conn.createstatement ();

转载请注明原文地址:https://www.9cbs.com/read-60803.html

New Post(0)