JDBC Connection

Explain the steps involved in creating JDBC connection?

Questions by winoth4   answers by winoth4

Showing Answers 1 - 6 of 6 Answers

Here I'm Using Type-4 Driver to connect to Oracle 10g application and there it goes


Step-1: JDBC Driver loading which will be as follows 
       Class.forName("oracle.jdbc.OracleDriver");
Step 2 : Establishing Connection to the loaded Driver 
       Connection con=DriverManager.getConnection ("jdbc:oracle:thin:@127.0.0.1:1521:xe","username","password");

Step 3: Creating the Statements for established Connection
       Statement st=con.createStatement();
       st.executeQuery("SQL QUERY");

Thus how you create a connection to Database from Java Application
Here is the sample code for JDBC Connection  using Type 4 Driver

import java.sql.*;
class ConnectDatabase 
{
public static void main(String[] args) throws Exception
{
Connection con;
Statement st;
Class.forName("oracle.jdbc.OracleDriver");
con= DriverManager.getConnection ("jdbc:oracle:thin:@127.0.0.1:1521:xe","system","tiger");
st=con.createStatement();
st.executeQuery("create table std(id number(1),name varchar2(25))");
}

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions