Sunday 3 March 2013

What are the main steps in java to make JDBC connectivity?


Load the Driver: 
·         First step is to load the database specific driver which communicates with database.

Syntax:          Class.forName(…);

Make Connection: 
·         Next step is get connection from the database using connection object, which is used to send SQL statement also and get result back from thedatabase.

Syntax:          Connection con=DriverManager.getConnection(…);

Get Statement object: 
·         From connection object we can get statement object which is used to query the database

Syntax:         Statement stmt=con.createStatement();

Execute the Query:
·         Using statement object we execute the SQL or database query and get result set from the query.

Syntax:          stmt.executeQuery(…);

Close the connection:
·         After getting resultset and all required operation performed the last step should be closing the database connection.

Syntax:          con.close();

No comments:

Post a Comment