//Note: create a DSN in the name of sql that is pointing the table name limbs in the database with three String column names things,legs,arms
//UPDATING ROWS NOT WORKING
//scrollable,sensitive concurent updatable record set
//records will be printed in reverse order
//updaing no of arms that means 3ed column
import java.sql.*;
import java.net.*;
class Jdbc8{
public static void main(String...arg) throws Exception{
System.out.println(InetAddress.getLocalHost());
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection c = DriverManager.getConnection("jdbc:odbc:sql");
Statement st = c.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,
ResultSet.CONCUR_UPDATABLE);
ResultSet r = st.executeQuery("select * from limbs");
try{
r.afterLast(); //working only with scrollable rs
while(r.previous()){
System.out.print(r.getString(1)+" ");
System.out.print(r.getString(2)+" ");
int arms = r.getInt(3);
arms = arms+5;
r.updateInt(3,arms);
System.out.println(r.getInt(3));
}
}catch(Exception e){System.out.println("Hello");e.printStackTrace();}
r.close();
st.close();
c.close();
}
}
No comments:
Post a Comment