Jdbc Part-2
Jdbc Part-2
JDBC part-2
Type - IV Driver (JDBC 100% Pure Java Driver):
It is also called as JDBC Native Protocol Driver (or) Thin Driver
Type - IV Driver Class Name for Oracle Database:
oracle.jdbc.driver.OracleDriver
URL to access driver:
jdbc:oracle:thin:@domain-name:port-no:service-id
Type - IV Driver Functionality:
It passes the java instructions directly to a database.
Advantages:
1) It is a highest performance driver as compared to all other drivers.
2) DSN not required.
3) Database not needed on same system.
4) It is suitable for applets.
Disadvantages:
1) Separate driver required for every database.
try{
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection
con=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe","syste
m","manager");
System.out.println("Connection Established Successfully");
}catch(Exception e)
{
System.err.println(e);
}
}
}
Statement interface:
It is used to execute static SQL queries.
PreparedStatement interface:
It is used to execute dynamic SQL queries.
CallableStatement interface:
It is used to execute PL/SQL programs.
execute() method:
It is suitable to execute DDL queries. DDL stands for Data Definition Language.
Examples: CREATE, ALTER, DROP, .. etc.,
executeUpdate() method:
It is suitable to execute DML queries. DML stands for Data Manipulation
Language.
Examples: INSERT, UPDATE, DELETE, .. etc.,
executeQuery() method:
It is suitable to execute DQL queries. DQL stands for Data Query Language.
Examples: SELECT
Connection
con=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe","syste
m","manager");
Statement stmt=con.createStatement();
stmt.execute("create table student(rollno number(3), name
varchar2(10), marks number(3))");
System.out.println("Table Created Successfully");
}catch(Exception e)
{
System.err.println(e);
}
}
}
}
System.out.println();
while(rs.next())
{
for(int i=1;i<=n;i++)
{
System.out.print(rs.getString(i)+"\t");
}
System.out.println();
}
}catch(Exception e)
{
System.err.println(e);
}
}
}
By