database and relative
  • Introduction
  • database
  • SQL
  • different kinds of Database
  • JDBC
  • oracle
  • MySQL
  • hibernate1
  • JavaPersistence:HibernateandJPAFundamentals0
  • keys
  • NoSQL DB
Powered by GitBook
On this page
  • 1. Fundamental steps in the JDBC
  • 2.Please always put any closing stuff in the finally block.
  • 3. exceptions
  • 4. Flow

Was this helpful?

JDBC

Previousdifferent kinds of DatabaseNextoracle

Last updated 5 years ago

Was this helpful?

1. Fundamental steps in the JDBC

  • import JDBC packages.

import oracle.jdbc.driver.*;
import oracle.sql.*;
import java.sql.*;
  • Load and register the JDBC driver.

DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
Class.forName("oracle.jdbc.driver.OracleDriver");
  • Open a connection to the database.

Connection conn = DriverManager.getConnection(URL, username, passwd);
Connection conn = DriverManager.getConnection(URL);
  • Create a statement object to perform a query.

Statement sql_stmt = conn.createStatement();
  • Execute the statement object and return a query resultset.

  • Process the resultset.

  • Close the resultset and statement objects.

  • Close the connection.

2.Please always put any closing stuff in the finally block.

3. exceptions

Exceptions in JDBC are usually of two types:

  • Exceptions occurring in the JDBC driver

  • Exceptions occurring in the Oracle 8i database itself

4. Flow

  • step1: import required packages

  • step2: Register JDBC driver

  • step3: open a connection

  • step4: execute a query

  • step5: extract data from result set

  • step6: clean-up environment

http://www.informit.com/articles/article.aspx?p=26251&seqNum=3