Wednesday, February 9, 2011

Getting Connection from DataBase

//get connection from DataBase using orclae or thin driver using jdbc api

import java.sql.*;
public class DBConnection
{
public static void main(String args[])
{
try
{
DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
System.out.println("thin driver is registerd");
Connection con=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe","system","system");
System.out.println("Connection is established to DB");

}
catch(Exception e)
{
e.printStackTrace();
System.out.println("Registeration faild");
}
}
}

/*
Explanation:

To get Connetion we has used "Connetion" interface
and getConnection method takes three parameters

1:URL
2:user name
3:password

*/

No comments:

Post a Comment