Various database drivers
Database Name |
|
Description |
MySQL |
Http://www.mysql.com/products/connector/j/ |
Shipped. but need to download the latest for MySQL 4.1 or higher. |
Oracle |
Http://sourceforge.net/project/showfiles.php? Group_id = 33291 Software/Tech/Java/sqlj_jdbc/index.html |
Encoded ded. |
SQL Server by jtds |
Http://sourceforge.net/project/showfiles.php? Group_id = 33291 |
Supported ded. Support Microsoft SQL Server (6.5, 7, 2000 and 2005) |
Postgres |
Http://jdbc.postgresql.org/download.html |
Supported ded 7.3 JDBC 3 |
SAP DB |
Http://www.sapdb.org/sap_db_jdbc.htm |
Encoded ded. |
Sybase by jtds |
Http://jtds.sourceforge.net/ |
Supported ded. Support Sybase (10, 11, 12) |
Various driver Connection Methods:
1. MySQL (http://www.mysql.com) mysql-connector-java-2.0.14-bin.jar;
Class. forname ("org. gjt. Mm. MySQL. Driver ");
CN = drivermanager. getconnection ("JDBC: mysql: // mydbcomputernameorip: 3306/mydatabasename", susr, spwd );
2. PostgreSQL (http://www.de.postgresql.org) pgjdbc2.jar;
Class. forname ("org. PostgreSQL. Driver ");
CN = drivermanager. getconnection ("JDBC: PostgreSQL: // mydbcomputernameorip/mydatabasename", susr, spwd );
3. Oracle (http://www.oracle.com/ip/deploy/database/oracle9i/) classes12.zip;
Class. forname ("oracle. JDBC. Driver. oracledriver ");
CN = drivermanager. getconnection ("JDBC: oracle: thin: mydbcomputernameorip: 1521: orcl", susr, spwd );
4. Sybase (http://jtds.sourceforge.net) jconn2.jar;
Class. forname ("com. Sybase. jdbc2.jdbc. sybdriver ");
CN = drivermanager. getconnection ("JDBC: Sybase: TDS: mydbcomputernameorip: 2638", susr, spwd );
// (Default-username/password: "dba"/"SQL ")
5. Microsoft sqlserver (http://jtds.sourceforge.net );
Class. forname ("net. SourceForge. jtds. JDBC. Driver ");
CN = drivermanager. getconnection ("JDBC: jtds: sqlserver: // mydbcomputernameorip: 1433/master", susr, spwd );
6. Microsoft sqlserver (http://www.microsoft.com );
Class. forname ("com. Microsoft. JDBC. sqlserver. sqlserverdriver ");
CN = drivermanager. getconnection ("JDBC: Microsoft: sqlserver: // mydbcomputernameorip: 1433; databasename = Master", susr, spwd );
7. ODBC
Class. forname ("Sun. JDBC. ODBC. jdbcodbcdriver ");
Connection Cn = drivermanager. getconnection ("JDBC: DBC:" + sdsn, susr, spwd );
8. DB2 class. forname ("com.ibm.db2.jdbc.net. db2driver ");
String url = "JDBC: DB2: // 192.9.200.108: 6789/sample"
CN = drivermanager. getconnection (URL, susr, spwd );
9. Because access does not run as a service, the URL method is not applicable to access. Access can be found in the form of ODBC or server ing paths, see http://rmijdbc.objectweb.org/Access/access.htmlI. Fast query of tables connected to various database Methods
The following lists the JDBC Connection Methods for various databases, which 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 indicates 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 indicates 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 indicates the Database Name Connection conn = drivermanager. getconnection (URL ); |
7. PostgreSQL database
Class. forname ("org. PostgreSQL. Driver"). newinstance (); String url = "JDBC: PostgreSQL: // localhost/mydb" // mydb indicates the database name. String user = "myuser "; String Password = "mypassword "; Connection conn = drivermanager. getconnection (URL, user, password ); |
8. Access database directly connected to 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 (); |
Ii. JDBC connection to MySQL
The following is a small tutorial on connecting to MySQL using JDBC.
1. Search driverProgram
MySQL currently provides the Java driver connection/J, can be downloaded from the MySQL official website, and find the mysql-connector-java-3.0.15-ga-bin.jar file, this driver is pure Java driver, do not need to do other configuration.
2. dynamically specify classpath
If you need to dynamically specify the classpath for execution, use the-CP method during execution. Otherwise, add the above. jar file to the classpath environment variable.
3. Load the driver
Try { Class. forname (COM. MySQL. JDBC. Driver ); System. Out. println (success loading MySQL driver !); } Catch (exception E) { System. Out. println (error loading MySQL driver !); E. printstacktrace (); } |
4. Set the connection URL
JDBC: mysql: // localhost/databasename [? Pa = VA] [& pa = VA] |