1, oracle8/8i/9i database (thin mode)
Class.forName ("Oracle.jdbc.driver.OracleDriver"). newinstance ();
String url= "Jdbc:oracle:thin: @localhost: 1521:ORCL";
ORCL is the SID of the database
String user= "Test";
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= "";
Connection conn= drivermanager.getconnection (Url,user,password);
3. SQL server7.0/2000 Database
Class.forName ("Com.microsoft.jdbc.sqlserver.SQLServerDriver"). newinstance ();
String url= "Jdbc:microsoft:sqlserver://localhost:1433;databasename=mydb";
MyDB as a database
String user= "SA";
String password= "";
Connection conn= drivermanager.getconnection (Url,user,password);
SQL Server Jtds Connection
<connection-url>jdbc:jtds:sqlserver://localhost:1433/test</connection-url>
<driver-class>net.sourceforge.jtds.jdbc.Driver</driver-class>
<user-name>sa</user-name>
<password>accp</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");
Connection conn= drivermanager.getconnection (URL, sysprops);
5. Informix Database
Class.forName ("Com.informix.jdbc.IfxDriver"). newinstance ();
String URL =
"Jdbc:informix-sqli://123.45.67.89:1533/mydb:informixserver=myserver;
User=testuser;password=testpassword ";
MyDB for Database name
Connection conn= drivermanager.getconnection (URL);
6. mysql Database
Class.forName ("Org.gjt.mm.mysql.Driver"). newinstance ();
Com.mysql.jdbc.Driver
String url = "jdbc:mysql://localhost/mydb?user=soft&password=soft1234&useunicode=true& Characterencoding=8859_1 "
Url= "JDBC:MYSQL://10.8.2.121:3306/MYDB?USEUNICODE=TRUE&AMP;CHARACTERENCODING=GBK"
MyDB for Database name
Connection conn= drivermanager.getconnection (URL);
7. PostgreSQL Database
Class.forName ("Org.postgresql.Driver"). newinstance ();
String url = "Jdbc:postgresql://localhost/mydb"
MyDB for Database name
String user= "MyUser";
String password= "MyPassword";
Connection conn= drivermanager.getconnection (Url,user,password);
8,//sqlserver 2005 Drive Connection
Class.forName (Com.microsoft.sqlserver.jdbc.SQLServerDriver);
String url= "Jdbc:sqlserver://localhost:1433;databasename=company";
Driver connection for SQL Server 2000
Class.forName (Com.microsoft.jdbc.sqlserver.SQLServerDriver);
String url= "Jdbc:microsoft:sqlserver://localhost:1433;databasename=company";
9, Access
To define a database driver
Private final static String DRIVER = "Sun.jdbc.odbc.JdbcOdbcDriver";
Defining a database connection address
Private final static String URL = "Jdbc:odbc:test";
public static Connection getconnection ()
{
Connection conn = null;
try{
To load a JDBC driver class into a Java virtual machine
Class.forName (DRIVER);
Get a connection
conn = Drivermanager.getconnection (URL);
}catch (Exception e) {
E.printstacktrace ();
}
Return conn;
}