Establishing the connection with DataBase Server

In order to establish a connection with DB server, first we need to know, which class is used to establish the connection. DriverManager is the class which contains the method named getConnection(). The following figure shows the syntax for this method. 
Syntax of getConneciton() method
Fig: method in DriverManager class that connects DBServer
      In the above diagram, observe the third syntax, it contains three parameters and it returns a Connection class object. Connection is an interface, but the class which implements this Connection interface is called as Connection class, the object of which this method returns. To store this object we should create a reference variable as follows. 
  • Connection con=DriverManager.getConnection("url ", " usr_name" , "psswrd" );
In the above syntax, since getConnection() is a static method we are calling it using its class name. Coming to the parameters, it has three parameters. The following program shows, how to connect with database.

program to establish connection with DBserver
Fig: program to establish connection with DBserver
  

2 comments:

  1. hi sir.
    this java student i have a doubt for this established connection then i got a error message ie

    G:\work>javac Createtable.java
    Createtable.java:4: package oracle.jdbc.driver does not exist
    DriverManager.registerDriver (new oracle.jdbc.driver.OracleDriver
    ^
    1 error

    ReplyDelete
  2. hi sir, this afrooz today i got error messages ie
    G:\work>javac Createtable.java
    Createtable.java:4: package oracle.jdbc.driver does not exist
    DriverManager.registerDriver (new oracle.jdbc.driver.OracleDriver
    ^
    1 error
    know how resolve the problems

    ReplyDelete