JDBC Various database connection methods

Source: Internet
Author: User
Tags informix postgresql sybase sybase database

1) Connect Oracle 8/8i/9i/10g/11g (thin mode)

Class.forName ("Oracle. JDBC.driver.OracleDriver "). newinstance ();

String url= "JDBC:oracle:thin: @localhost: 1521:orcl"//ORCL the SID for the Oracle database

String user= "Test";

String password= "Test";

Connection con=drivermanager.getconnection (Url,user,password);

2) Connect DB2 database

Class.forName ("Com.ibm.db2.jcc.DB2Driver");

String url= "Jdbc:db2://localhost:5000/testdb";

String user= "Test"; String password= "Test";

Connection con=drivermanager.getconnection (Url,user,password);

3) connect to MySQL Database

Class.forName ("Com.mysql.jdbc.Driver");

String url= "Jdbc:mysql://localhost:8080/testdb";

String user= "Test"; String password= "Test";

Connection con=drivermanager.getconnection (Url,user,password);

4) Connect the SQL Server2000 database

Class.forName ("Com.microsoft.JDBC.sqlserver.SQLServerDriver");

String url= "Jdbc:microsoft:sqlserver://localhost:1433;databasename=testdb";

String user= "Test"; String password= "Test";

Connection con=drivermanager.getconnection (Url,user,password);

5) Connect the PostgreSQL database

Class.forName ("Org.postgresql.Driver");

String url= "Jdbc:postgresql://localhost/testdb";

String user= "Test"; String password= "Test";

Connection con=drivermanager.getconnection (Url,user,password);

6) Connect to an Access database

Class.forName ("Sun.jdbc.odbc.JdbcOdbcDriver");

String url= "Jdbc:odbc:driver={microsoft Access Driver (*.mdb)};D bq=" +application.getrealpath ("/data/testdb/mdb");

Connection conn=drivermanager.getconnection (URL, "", "");

7 Connecting the Sybase database

Class.forName ("Com.sybase.JDBC.SybDriver");

String url= "Jdbc:sybase:tds:localhost:5007/testdb";

Properties pro=system.getproperties ();

Pro.put ("User", "userId");

Pro.put ("Password", "User_password");

Connection con=drivermanager.getconnection (Url,pro);

8 Connecting to the Informix database

Class.forName ("Com.informix.JDBC.ifxDriver");

String url= "Jdbc:informix-sqli:localhost:1533/testdb:informixserver=myserver" user=testuser;password= Testpassword "; Connection con=drivermanager.getconnection (URL);

JDBC Various database connection methods

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.