Various Java database connections

Source: Internet
Author: User

MySQL:
String driver = "com. MySQL. JDBC. Driver"; // driver
String url = "JDBC: mysql: // localhost: 3306/db_name"; // connection URL. db_name indicates the database name.
String username = "username"; // User Name
String Password = "password"; // Password
Class. forname (driver). New instance ();
Connection con = drivermanager. getconnection (URL, username, password );
Microsoft SQL Server 2.0 Driver (the one with Three jar files ):
String driver = "com. Microsoft. JDBC. sqlserver. sqlserverdriver"; // Method for connecting to the SQL database
String url = "JDBC: Microsoft: sqlserver: // localhost: 1433; databasename = db_name"; // db_name indicates the 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 (the one in one jar): // well-developed by lazizhu
String driver = "com. Microsoft. sqlserver. JDBC. sqlserverdriver"; // Method for connecting to the SQL database
String url = "JDBC: Microsoft: sqlserver: // localhost: 1433; databasename = db_name"; // db_name indicates the 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
String url = "JDBC: sysbase: // localhost: 5007/db_name"; // db_name indicates the 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"; // database connection method
String url = "JDBC: oracle: thin: @ loaclhost: 1521: orcl"; // orcl indicates the SID of the database.
String username = "username"; // User Name
String Password = "password"; // Password
Class. forname (driver). newinstance (); // load the database driver
Connection con = drivermanager. getconnection (URL, username, password );
PostgreSQL:
String driver = "org. PostgreSQL. Driver"; // database connection method
String url = "JDBC: PostgreSQL: // localhost/db_name"; // db_name indicates the 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"; // connect to a provider instance with a DB2 Client
// String driver = "com.ibm.db2.jdbc.net. db2.driver"; // connect a provider instance that does not have a DB2 Client
String url = "JDBC: DB2: // localhost: 5000/db_name"; // db_name indicates the 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 indicates the 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 indicates the data source name.
String username = "username"; // User Name
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.