Java connectivity Six classes of database skills full Raiders _java

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

Small series in this article will mainly introduce Java and Oracle, DB2, SQL Server, Sybase, MySQL, PostgreSQL and other database connection methods.

1. Oracle Database

Class.forName ("Oracle.jdbc.driver.OracleDriver"). newinstance (); 
 
String url= "Jdbc:oracle:thin: @localhost: 1521:ORCL"; 
 
ORCL the SID 
 
String user= "test" for 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 for your database name 
 
String user= "admin"; 
 
String password= ""; 
 

3. SQL Server 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= ""; 
 

4. Sybase database

Class.forName ("Com.sybase.jdbc.SybDriver"). newinstance (); 
 
String url = "Jdbc:sybase:tds:localhost:5007/mydb"; 
 
MyDB for your database name 
 
Properties sysprops = system.getproperties (); 
 
Sysprops.put ("User", "userid"); 
 
Sysprops.put ("Password", "User_password"); 
 

5. 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 for database name 
 

6. PostgreSQL database

Class.forName ("Org.postgresql.Driver"). newinstance (); 
 
String url = "Jdbc:postgresql://localhost/mydb" 
 
//mydb the database name 
 
string user= "MyUser"; 
 
String password= "MyPassword"; 
 

The above is the Java connection of various types of database skills, I believe it will be able to realize the Java Connection database Help.

Related Article

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.