Java connection to various database code __ database

Source: Internet
Author: User
Tags db2 informix microsoft sql server odbc postgresql

Mysql:string driver= "Com.mysql.jdbc.Driver"; Driver Program

String url= "Jdbc:mysql://localhost:3306/db_name"; The url,db_name of the connection is the database name

String username= "Username";    User name String password= "Password"; Password

Ways to connect to SQL databases

Class.forName (Driver). New Instance (); Connection con=drivermanager.getconnection (Url,username,password); Microsoft SQL Server 2.0 driver (one of 3 jars): String driver= "Com.microsoft.jdbc.sqlserver.SQLServerDriver";

String url= "Jdbc:microsoft:sqlserver://localhost:1433;databasename=db_name"; Db_name for Database name

String username= "Username";    User name String password= "Password"; Password

Class.forName (Driver). New Instance (); Load data to drive

Connection con=drivermanager.getconnection (Url,username,password); Microsoft SQL Server 3.0 driver (one of 1 jars):

Old Zi Zhu Perfect String driver= "Com.microsoft.sqlserver.jdbc.SQLServerDriver"; Ways to connect to SQL databases

String url= "Jdbc:microsoft:sqlserver://localhost:1433;databasename=db_name"; Db_name for Database name

String username= "Username";    User name String password= "Password"; Password

Class.forName (Driver). New Instance (); Load data to drive

Connection con=drivermanager.getconnection (Url,username,password);    Sysbase:string driver= "Com.sybase.jdbc.SybDriver"; Driver Program

String url= "Jdbc:sysbase://localhost:5007/db_name"; Db_name is a data name

String username= "Username";    User name String password= "Password"; Password

Class.forName (Driver). newinstance (); Connection con=drivermanager.getconnection (Url,username,password);    Oracle (in thin mode): String driver= "Oracle.jdbc.driver.OracleDriver"; Ways to connect to a database

ORCL is the SID of the database

String url= "Jdbc:oracle:thin: @loaclhost: 1521:ORCL";

String username= "Username";    User name String password= "Password"; Password

Class.forName (Driver). newinstance (); Load Database Driver

Connection con=drivermanager.getconnection (Url,username,password);    Postgresql:string driver= "Org.postgresql.Driver"; Ways to connect to a database

String url= "Jdbc:postgresql://localhost/db_name"; Db_name is a data name

String username= "Username";    User name String password= "Password"; Password

  Class.forName (Driver). newinstance ();       

Connection con=drivermanager.getconnection (Url,username,password); DB2:     String driver= "Com.ibm.db2.jdbc.app.DB2.Driver";   //Connection DB2 instance with provider client    //string driver= "Com.ibm.db2.jdbc.net.DB2.Driver";   //Connection DB2 instance with no provider client     String url= "Jdbc:db2://localhost:5000/db_name";   //db_name for Data name      String Username= "Username";   //user name     String password= "Password";    //Password     class.forname (Driver) newinstance ();        Connection con=drivermanager.getconnection (Url,username,password); Informix:     String driver= "Com.informix.jdbc.IfxDriver";        String url= "Jdbc:informix-sqli://localhost:1533/db_name:informixser=myserver";   //db_name for Data name     String username= "Username";   //user name     String password= "Password";   //Password     class.forname (Driver). newinstance ();         Connection con=drivermanager.getconnection (Url,username,password); JDBC-ODBC:     String driver= "Sun.jdbc.odbc.JdbcOdbcDriver";     string Url= "Jdbc:odbc:dbsource";   //dbsource for data source name     String Username= "Username";   //username     String password= "Password";   //password     Class.forName (Driver). newinstance ();        Connection con= Drivermanager.getconnection (Url,username,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.