JDBC

JDBC ( Java Data-Base Connectivity ) - A platform-neutral API for connecting to DBs and supplying low-level support for SQL functionality.

Emphasis is on how to find the data and not what to find.

SQL ( Structured Query Language ) - A non-procedural language for interaction with an RDBMS, developed by IBM in 70s-80s.
  • DDL (Data Definition Lang.) Subset of SQL commands for defining tables, columns and for adding and removing table entries, includes CREATE, DROP, ALTER commands.
  • DML (Data Maintenance Lang.) Subset of SQL used to manipulate the data in tables using INSERT, DELETE and UPDATE.
  • DQL (Data Query Lang.) Used to retrieve data from tables using SELECT, etc.


Oracle.java
Illustrates the 5 Steps of JDBC
import java.sql.*;
import java.io.*;

public class oracle
{
   public static void main(String args[])
   {
    try{
//  1. Load the Driver 
        Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
//  2. Create Connection 
        Connection con = DriverManager.getConnection("jdbc:odbc:sam","euser","pwd");
//  3. Create Statement 
        Statement stmt = con.createStatement();
//  4. Execute SQL Query 
        ResultSet rs = stmt.executeQuery("SELECT ename, sal FROM emp"):
//  5. Iterate Resultset 
        boolean flag = rs.next();
        while( flag )
          {
           System.out.println(rs.getString("ename")+rs.getInt("sal");
           flag = rs.next();
          }
        }
     catch(Exception e) { }
    }
}

[ Index ]