import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class UpdatableResultSet {
public static void main(String[] args){
Connection con = null;
Statement stmt = null;
ResultSet rs = null;
try {
Class.forName("org.apache.derby.jdbc.ClientDriver");
String url = "jdbc:derby://localhost:1527/hari";
con = DriverManager.getConnection(url, "app","app");
stmt = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
String query = "select * from MYEMP";
rs = stmt.executeQuery(query);
while(rs.next()){
if(rs.getInt(1)== 11){
rs.updateString(2, "Sachin");
rs.updateFloat(3, 33333);
rs.updateString("ADDRESS", "Mumbai"); // either we can use position or field name.
rs.updateRow();
}
}
} catch (ClassNotFoundException ex) {
ex.printStackTrace();
}catch (SQLException ex1) {
ex1.printStackTrace();
}
}
}
No comments:
Post a Comment