jdbc

May 13th, 2011No Comments

step 1: Get the Connection object.

step 2: Get the Statement object.

step 3: Bind the parameters to SQL query.

step 4: Execute the SQL query.

step 5: Process the result.

step 6: Close the connections and take care of exceptions.

 

example code: /*using Oracle express edition and username: sys and pwd: rt*/

import java.sql.*;

public class JdbcDemo {

try {

Class.forName(“oracle.jdbc.driver.OracleDriver”);

Connection c;

c=DriverManager.getConnection(“jdbc:oracle:thin@localhost:1521:XE”,”sys”,”rt”);

Statement s=c.CreateStatement();

s.executeUpdate(“insert into emp values(100,’abc’);

ResultSet rs=s.executeQuery(“select * from emp”);

System.out.println(rs);

c.close();

}catch(Exception e){

System.out.println(e);

}

}

}

VN:F [1.9.10_1130]
Rating: 9.0/10 (3 votes cast)
VN:F [1.9.10_1130]
Rating: +5 (from 5 votes)

jdbc , 9.0 out of 10 based on 3 ratings

About author:

All entries by

Leave a Reply