Java JDBC DRIVER

xiaoxiao2021-03-06  96

Java connection to various databases Source: Net all world

The code in this article mainly lists the key code of the connection database, and other access database code is omitted.

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" of the database; 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 you Database name string user = "admin"; string password = "; connection conn = drivermanager.getConnection (URL, User, Password);

3, SQL Server 7.0 / 2000 database class.Forname ("com.microsoft.jdbc.sqlser.sqlserverdriver). Newinstance (); string url =" JDBC: Microsoft: SQLServer: // localhost: 1433; databasename = mydb " ; // mydb is the 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 is a 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. Connect to the ODBC: Drivers = sun.jdbc.odbc.jdbcodbcdbdriverlogfile = c: //dbconnectionmanager.logidb.maxconn=10idb.url=jdbc: odbc: vfpidb.user = idb.password =

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

New Post(0)