Using UpdatableResultSet to insert a new row : ResultSet Updatable « Database SQL JDBC « Java






Using UpdatableResultSet to insert a new row

  


import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;

public class PrintResultSet {
  public static void main(String args[]) throws Exception {
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    Connection con = DriverManager.getConnection("jdbc:odbc:Contacts");
    Statement stmt = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE);
    ResultSet rs = stmt.executeQuery("select * from employee");
    rs.moveToInsertRow();

    rs.updateInt("Contact_ID", 150);
    rs.updateString("First_Name", "Nigel");
    rs.updateString("Last_Name", "Thornebury");

    rs.insertRow();
  }
}

   
  








Related examples in the same category

1.If database support updatable result sets
2.Delete Row from Updatable ResultSet for MySQL
3.Insert Row to Updatable ResultSet from MySQL
4.Make updates in Updatable ResultSet
5.Demo Updatable ResultSet
6.Updatable resultset with Oracle Driver
7.Determining If a Database Supports Updatable Result Sets: An updatable result set allows modification to data in a table through the result set.
8.Creating an Updatable Result Set
9.Determining If a Result Set Is Updatable
10.Updating a Row in a Database Table Using an Updatable Result Set
11.Cancelling Updates to an Updatable Result Set
12.Inserting a Row into a Database Table Using an Updatable Result Set
13.Deleting a Row from a Database Table Using an Updatable Result Set
14.Refreshing a Row in an Updatable Result Set