ResultSet: insertRow() : ResultSet « java.sql « Java by API





ResultSet: insertRow()

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

public class Main {

  public static void main(String[] args) throws Exception {
    String driver = "sun.jdbc.odbc.JdbcOdbcDriver";

    Connection con;
    Statement stmt;
    ResultSet uprs;

    try {
      Class.forName(driver);
      con = DriverManager.getConnection("jdbc:odbc:RainForestDSN", "student","student");
      stmt = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
      uprs = stmt.executeQuery("SELECT * FROM Records");

      // Check the column count
      ResultSetMetaData md = uprs.getMetaData();
      System.out.println("Resultset has " + md.getColumnCount() + " cols.");

      int rowNum = uprs.getRow();
      System.out.println("row1 " + rowNum);
      uprs.absolute(1);
      rowNum = uprs.getRow();
      System.out.println("row2 " + rowNum);
      uprs.next();
      uprs.moveToInsertRow();
      uprs.updateInt(1, 150);
      uprs.updateString(2, "Madonna");
      uprs.updateString(3, "Dummy");
      uprs.updateString(4, "Jazz");
      uprs.updateString(5, "Image");
      uprs.updateInt(6, 5);
      uprs.updateDouble(7, 5);
      uprs.updateInt(8, 15);
      uprs.insertRow();
      uprs.close();
      stmt.close();
      con.close();
    } catch (SQLException ex) {
      System.err.println("SQLException: " + ex.getMessage());
    }
  }
}

           
         
  










Related examples in the same category

1.ResultSet.CLOSE_CURSORS_AT_COMMIT
2.ResultSet.CONCUR_READ_ONLY
3.ResultSet.CONCUR_UPDATABLE
4.ResultSet.HOLD_CURSORS_OVER_COMMIT
5.ResultSet.TYPE_SCROLL_INSENSITIVE
6.ResultSet.TYPE_SCROLL_SENSITIVE
7.ResultSet: TYPE_FORWARD_ONLY
8.ResultSet: absolute(int row)
9.ResultSet: beforeFirst()
10.ResultSet: cancelRowUpdates()
11.ResultSet: close()
12.ResultSet: deleteRow()
13.ResultSet: first()
14.ResultSet.getAsciiStream(int columnIndex)
15.ResultSet: getBinaryStream(int columnIndex)
16.ResultSet: getBigDecimal(int columnIndex)
17.ResultSet: getBlob(int columnIndex)
18.ResultSet: getBlob(String colName)
19.ResultSet: getBytes(int columnIndex)
20.ResultSet: getClob(int columnIndex)
21.ResultSet: getConcurrency()
22.ResultSet: getDate(int columnIndex)
23.ResultSet: getDouble(String columnLabel)
24.ResultSet: getInt(int columnIndex)
25.ResultSet: getInt(String columnName)
26.ResultSet: getMetaData()
27.ResultSet: getObject(int columnIndex)
28.ResultSet: getObject(String columnLabel)
29.ResultSet: getRef(int columnIndex)
30.ResultSet: getRow()
31.ResultSet: getShort(String columnLabel)
32.ResultSet: getString(int columnIndex)
33.ResultSet: getString(String columnLabel)
34.ResultSet: getTime(int columnIndex)
35.ResultSet: getTimestamp(int columnIndex)
36.ResultSet: getType()
37.ResultSet: getWarnings()
38.ResultSet: isAfterLast()
39.ResultSet: isBeforeFirst()
40.ResultSet: isFirst()
41.ResultSet: last()
42.ResultSet: moveToInsertRow()
43.ResultSet: next()
44.ResultSet: previous()
45.ResultSet: refreshRow()
46.ResultSet: relative(int rows)
47.ResultSet: setFetchSize(int rows)
48.ResultSet: updateInt(String columnLabel, int x)
49.ResultSet: updateRow()
50.ResultSet: updateDouble(int columnIndex, double x)
51.ResultSet: updateString(String columnName, String x)
52.ResultSet: wasNull()