JDBC
Create Connections!!!

This page tells you various ways to create database connection.

No theory! Follow the steps and you are done.

 

Connection through DSN:

 

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con = DriverManager.getConnection("jdbc:odbc:DSN_Name","username","password");

 

To create DSN:

 

programs -> settings -> control panel -> administrative tools -> data sources (ODBC)

 

create a new DSN here.

 

Thin Driver:

 

Take classes11.zip into class path.

 

Class.forName("oracle.jdbc.driver.OracleDriver");

Connection con = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1526:Database_Name", "system", "manager");

 

To Know Database Name:

1] open a command prompt and type ‘net start’

2] open a command prompt and type ‘services.msc’

 

This will list down all the services, one of the entry will be like this:

 

oracleservice_SHREE

 

Here ‘_SHREE’ is Database Name

 

OCI8 Driver:

 

Take classes11.zip into class path.

 

Class.forName("oracle.jdbc.driver.OracleDriver");

Connection con = DriverManager.getConnection("jdbc:oracle:oci8:@TNS_Name", "system", "manager");

 

To Know TNS Name:

 

Search ‘tnsnames.ora’ file

 

A TNS Entry look like this:

 

SUNILDB =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP) (HOST = SUNIL01) (PORT = 1521))
)
(CONNECT_DATA =
(SID = SUNILDB)
(SERVER=DEDICATED)
)
)

 

Here TNS Name is ‘SUNILDB’