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 of the database
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 is 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.sqlserver.sqlserverdriver). NewInstance ();
String Url = "JDBC: Microsoft: SQLServer: // localhost: 1433; DatabaseName = MYDB";
// mydb is a 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 is 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 the 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);