JDBC connection string

Source: Internet
Author: User
Tags informix sybase sybase database

JDBC connection string
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"
"JDBC: mysql: // localhost/mytest? User = root & Password = root "+" & useunicode = true & characterencoding = GBK"
// 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 ();

Connection string in SQL Server 2000:
Driver = "com. Microsoft. JDBC. sqlserver. sqlserverdriver ";
Url = "JDBC: Microsoft: sqlserver: // 111.1.1.20.: 1433; databasename = ssodemo; user = sa; Password = 1 ";

Connection string in SQL Server 2005:
Driver = "com. Microsoft. sqlserver. JDBC. sqlserverdriver ";

Url = "JDBC: sqlserver: // 111.1.1.20.: 1433; databasename = ssodemo; user = sa; Password = 1 ";


Used

MySQL:

Class. forname ("com. MySQL. JDBC. Driver ");

String url = "JDBC: mysql: // localhost: 3306/test ";

Test indicates the database name.

Sqlserver2005:

Class. forname ("com. Microsoft. sqlserver. JDBC. sqlserverdriver ");

String url = "JDBC: sqlserver: // localhost: 1433; databasename = WHPU ";

ORACLE:

Class. forname ("oracle. JDBC. Driver. oracledriver"); // Oracle driver

String url = "JDBC: oracle: thin :@ localhost: 1521: orcl ";

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.