Common database connection string

Source: Internet
Author: User
Tags informix sybase sybase database

Database connection string

1. MySQL (http://www.mysql.com) Mm. mysql-2.0.2-bin.jar

Class. forname ("org. gjt. Mm. MySQL. Driver ");

CN = drivermanager. getconnection ("JDBC: mysql: // mydbcomputernameorip: 3306/mydatabasename", susr, spwd );

Com. MySQL. JDBC. Driver
JDBC: mysql: // [host: Port]/[database] [? Parameter Name 1] [= parameter value 1] [& parameter name 2] [= parameter value 2]...

Parameter Name Parameter description Default Value Minimum Version requirements
User Database username (used to connect to the database) All Versions
Password User Password (used to connect to the database) All Versions
Useunicode Whether to use the Unicode character set. If the characterencoding parameter is set to gb2312 or GBK, the value of this parameter must be set to true. False 1.1 GB
Characterencoding Specify the character encoding when useunicode is set to true. For example, you can set it to gb2312 or GBK. False 1.1 GB
Autoreconnect Will the database be automatically reconnected when the database connection is interrupted abnormally? False 1.1
Autoreconnectforpools Whether to use the reconnection policy for the database connection pool False 3.1.3
Failoverreadonly After automatic reconnection is successful, is the connection set to read-only? True 3.0.12
Maxreconnects Number of Retries when autoreconnect is set to true 3 1.1
Initialtimeout The interval between two reconnection attempts when autoreconnect is set to true. Unit: seconds. 2 1.1
Connecttimeout Timeout when establishing a socket connection with the database server, in milliseconds. 0 indicates never timeout. Applicable to JDK 1.4 and later versions. 0 3.0.1
Sockettimeout Socket operation (read/write) Timeout, in milliseconds. 0 indicates never timeout 0 3.0.1

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/ connector 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: ODBC:" + 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 );

\\\\\
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 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. ODBC bridging
Class. forname ("Sun. JDBC. ODBC. jdbcodbcdriver"); // load the JDBC-ODBC driver
Strcon = "JDBC: ODBC: test_db"; // sets the database connection string, test_db
Strcon = "JDBC: ODBC:; driver = {Microsoft Access Driver (*. mdb)}; DBQ = path \ database name"; // anonymous connection, no ODBC data source needs to be configured
Strcon = "JDBC: ODBC:; driver = {SQL Server}; server = host name \ Instance name; database = database name"; // anonymous connection, no ODBC data source needs to be configured

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.