Standard steps
for developing JDBC code:
A)
Register
JDBC driver s/w with DriverManager
B)
Establish
the connection with Database s/w
C)
Create
JDBC statement obj
D)
Send
and execute SQL query in db s/w
E)
Get
Result from db s/w and process the result
F)
Close
the connection with db s/w
Example :-
}
Example :-
public static void main(String[]
args)throws Exception {
//register
jdbc driver
Class.forName("oracle.jdbc.driver.OracleDriver");
//Establish the connection Connection
con=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe","system","manager");
//create Statement obj
Statement
st=con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,
ResultSet.CONCUR_UPDATABLE);
//create ResultSet obj
ResultSet rs=st.executeQuery("Select
sno,sname,sadd from student");
//process the ResultSet
int cnt=0;
while(rs.next()){
if(cnt==0)
Thread.sleep(20000);
rs.refreshRow();
System.out.println(rs.getInt(1)+" "+rs.getString(2)+" "+rs.getString(3));
cnt++;
}
No comments:
Post a Comment