JDBC to connect to the database on skills highlights

Java Database Connectivity (JDBC) consists of a set of classes and interfaces written in the Java programming language. JDBC provides a standard API tool / database developers, enabling them to write database applications using pure Java API. Various developers, however, the interface is not exactly the same, so the development of changes in the environment will bring some configuration changes. In this paper, a collection of different database connection.

A connecting various databases Fact Sheet

The following list of the various databases using 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 database SID
String user = “test”;
String password = “test”;
Connection conn = DriverManager.getConnection (url, user, password);

2, DB2 database

Class.forName (“the 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.sqlserver.SQLServerDriver”). NewInstance ();
String url = “jdbc: microsoft: sqlserver :/ / localhost: 1433; DatabaseName = mydb”;
/ / MyDB as database
String user = “sa”;
String password = “”;
Connection conn = DriverManager.getConnection (url, user, password);

4, the Sybase database

Class.forName (“com.sybase.jdbc.SybDriver”). NewInstance ();
String url = “jdbc: sybase: Tds: localhost: 5007/myDB” ;/ / myDB for your database name
The 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 for 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 as database name
Connection conn = DriverManager.getConnection (url);

7, PostgreSQL database

Class.forName (“org.postgresql.Driver”). NewInstance ();
String url = “jdbc: postgresql :/ / localhost / myDB” / / myDB for the database name
String user = “myuser”;
String password = “mypassword”;
Connection conn = DriverManager.getConnection (url, user, password);

Access the database directly used in conjunction with ODBC

The 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 ();