Content Marketing Is More Than
Just Creating Content.
Welcome to the iOPW Blog.

Commonly-used Databases Connection Methods

Commonly-used Databases Connection Methods

//MySQL:
String Driver="com.mysql.jdbc.Driver";    //Driver
String URL="jdbc:mysql://localhost:3306/db_name";    //connection URL, db_name is database name
String Username="username";    //Username    
String Password="password";    //Password
Class.forName(Driver).new Instance();     
Connection con=DriverManager.getConnection(URL,Username,Password);

//Microsoft SQL Server 2.0 Driver (contains 3 jar packages):   
String Driver="com.microsoft.jdbc.sqlserver.SQLServerDriver";    //the method of connecting to database
String URL="jdbc:microsoft:sqlserver://localhost:1433;
DatabaseName=db_name";      //db_name is database name
String Username="username";    //Username
String Password="password";    //Password  
Class.forName(Driver).new Instance();    //Load database driver
Connection con=DriverManager.getConnection(URL,UserName,Password);   

//Microsoft SQL Server 3.0 Driver (contains 1 jar package): 
String Driver="com.microsoft.sqlserver.jdbc.SQLServerDriver";    //the method of connecting to database
String URL="jdbc:microsoft:sqlserver://localhost:1433;
DatabaseName=db_name";    //db_name is database name    
String Username="username";    //Username
String Password="password";    //Password     
Class.forName(Driver).new Instance();    //Load database driver     
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 is database name  
String Username="username";    //Username
String Password="password";    //Password   
Class.forName(Driver).newInstance();    
Connection con=DriverManager.getConnection(URL,Username,Password);

//Oracle (use thin pattern):   
String Driver="oracle.jdbc.driver.OracleDriver";    //the method of connecting to database 
String URL="jdbc:oracle:thin:@loaclhost:1521:orcl";  //orcl is database SID    
String Username="username";    //Username
String Password="password";    //Password   
Class.forName(Driver).newInstance();    //Load database driver
Connection con=DriverManager.getConnection(URL,Username,Password);  

//PostgreSQL:    
String Driver="org.postgresql.Driver";    //the method of connecting to database   
String URL="jdbc:postgresql://localhost/db_name";    //db_name is database name 
String Username="username";    //Username 
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 which has a DB2 Client
//String Driver="com.ibm.db2.jdbc.net.DB2.Driver";  //Connect to a Provider instance which does not have a DB2 Client
String URL="jdbc:db2://localhost:5000/db_name";    //db_name is database client
String Username="username";    //Username
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 is database name
String Username="username";    //Username
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 is data source name
String Username="username";    //Username
String Password="password";    //Password
Class.forName(Driver).newInstance();
Connection con=DriverManager.getConnection(URL,Username,Password);