Java database connection code

Source: Internet
Author: User

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 string user = "test" of the database "; 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 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 the 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 );

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.