JDBC Driver

There are four type of JDBC Driver:


1. Type I: JDBC-ODBC Bridge Driver
2. Type II:  Partial Native Partial Java Driver
3. Type III: Net Protocol Drive
4. Type IV: Pure Java Driver


Type I Driver:  JDBC-ODBC Bridge Driver

Name:  JDBC-ODBC Bridge Driver

Vendor : Sun

Software: JDK

Path: e:\j2sdk1.4.2\bin

Classpath: e:\j2sdk1.4.2\bin

Driver Class: sun.jdbc.odbc.jdbcOdbcDriver

Url: jbdc:odbc:dsn

Username :database user name

Password: database password

Example:

Create a table:

create table customers( cid number(4);
                                    cname char(10);
                                    email char(20);
                                    )

Now java program:

import java.sql.*;

class JDBCExample{
                               public static void main(String as[]){
                                
                                 try{
                                  //load the driver
                                 Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
                                 // Get connection
                                  Connection con = DriverManager.getConnection("jdbc:odbc:B26DSN","username","password");
                                 //Create statement
                             Statement st=con.createStatement();
                            //prepare sql query
                         String sql="insert into customers values(101,'arbind','arbind@gmail.com');
                   //submit sql query
               int x=st.executeUpdate(sql);
              if(x==1){
                           System.out.println("Data inserted Successfully");
                           }
                        else{
                              System.out.println("Not inserted");
                             }
                //cleanup
              st.close();
            con.close();
}
catch(SQLException ex){
                System.out.println(ex.getMessage());
}
}
}

Type II Driver:  Partial Native Partial Java Driver

Name:  Partial Native Partial Java Driver

Vendor: DB Vendor

Software:Client Server DB

Path:--

Classpath:--

Driver Class:oracle.jdbc.driver.OracleDriver

Url:jdbc:oracle:oci8:@host:port:service

Username :database user name

Password: database password

 Type III: Net Protocol Drive

 Name : Net Protocol Driver

Vendor: IDS Software

 Type IV: Pure Java Driver




Name : Pure Java Driver




Vendor: DB Vendor




Software: Enterprise Edition




Configuration for




Oracle:


classpath: set classpath
Driver Class: oracle.jadbc.driver.OracleDriver
Url: jdbc:oracle:thin:@host:port:service
//eg. jdbc:oracle:thin:@localhost:1521:XE
username: system
password: yourpassword




For
MySql




classpath: set classpath
Driver Class:com.mysql.jdbc.Driver
Url:jdbc:mysql://host:port/database_name
//jdbc:mysql://localhost:3306/yourdatabase
username:root
password: yourpassword