List of usage examples for java.sql ResultSet updateInt
void updateInt(String columnLabel, int x) throws SQLException;
int
value. From source file:Main.java
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();//from ww w .j a v a 2 s . com rs.updateInt(1, 150); rs.updateString("First_Name", "Nigel"); rs.updateString("Last_Name", "Thornebury"); rs.insertRow(); }
From source file:Main.java
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();/* www .j a v a 2s . c o m*/ rs.updateInt("Contact_ID", 150); rs.updateString("First_Name", "Nigel"); rs.updateString("Last_Name", "Thornebury"); rs.insertRow(); }
From source file:InsertRow.java
public static void main(String args[]) { String url = "jdbc:mySubprotocol:myDataSource"; Connection con;//w ww .j ava 2 s. c o m Statement stmt; String query = "select COF_NAME, PRICE from COFFEES"; try { Class.forName("myDriver.ClassName"); } catch (java.lang.ClassNotFoundException e) { System.err.print("ClassNotFoundException: "); System.err.println(e.getMessage()); } try { con = DriverManager.getConnection(url, "myLogin", "myPassword"); stmt = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE); ResultSet uprs = stmt.executeQuery("SELECT * FROM COFFEES"); uprs.moveToInsertRow(); uprs.updateString("COF_NAME", "Kona"); uprs.updateInt("SUP_ID", 150); uprs.updateFloat("PRICE", 10.99f); uprs.updateInt("SALES", 0); uprs.updateInt("TOTAL", 0); uprs.insertRow(); uprs.beforeFirst(); System.out.println("Table COFFEES after insertion:"); while (uprs.next()) { String s = uprs.getString("COF_NAME"); int sup = uprs.getInt("SUP_ID"); float f = uprs.getFloat("PRICE"); int sales = uprs.getInt("SALES"); int t = uprs.getInt("TOTAL"); System.out.print(s + " " + sup + " " + f + " "); System.out.println(sales + " " + t); } uprs.close(); stmt.close(); con.close(); } catch (SQLException ex) { System.err.println("SQLException: " + ex.getMessage()); } }
From source file:InsertRows.java
public static void main(String args[]) { String url = "jdbc:mySubprotocol:myDataSource"; Connection con;/*from w ww .j a v a 2 s . com*/ Statement stmt; try { Class.forName("myDriver.ClassName"); } catch (java.lang.ClassNotFoundException e) { System.err.print("ClassNotFoundException: "); System.err.println(e.getMessage()); } try { con = DriverManager.getConnection(url, "myLogin", "myPassword"); stmt = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE); ResultSet uprs = stmt.executeQuery("SELECT * FROM COFFEES"); uprs.moveToInsertRow(); uprs.updateString("COF_NAME", "Kona"); uprs.updateInt("SUP_ID", 150); uprs.updateFloat("PRICE", 10.99f); uprs.updateInt("SALES", 0); uprs.updateInt("TOTAL", 0); uprs.insertRow(); uprs.updateString("COF_NAME", "Kona_Decaf"); uprs.updateInt("SUP_ID", 150); uprs.updateFloat("PRICE", 11.99f); uprs.updateInt("SALES", 0); uprs.updateInt("TOTAL", 0); uprs.insertRow(); uprs.beforeFirst(); System.out.println("Table COFFEES after insertion:"); while (uprs.next()) { String name = uprs.getString("COF_NAME"); int id = uprs.getInt("SUP_ID"); float price = uprs.getFloat("PRICE"); int sales = uprs.getInt("SALES"); int total = uprs.getInt("TOTAL"); System.out.print(name + " " + id + " " + price); System.out.println(" " + sales + " " + total); } uprs.close(); stmt.close(); con.close(); } catch (SQLException ex) { System.err.println("SQLException: " + ex.getMessage()); } }
From source file:Main.java
public static void main(String[] args) throws Exception { Class.forName("com.mysql.jdbc.Driver"); Connection connection = DriverManager.getConnection("jdbc:mysql://localhost/testdb", "root", ""); Statement statement = connection.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE); String query = "SELECT id, code, name, quantity, price FROM products"; ResultSet uprs = statement.executeQuery(query); while (uprs.next()) { System.out.println(uprs.getString("id") + ":" + uprs.getString("code") + ":" + uprs.getString("name") + ":" + uprs.getInt("quantity") + ":" + uprs.getDouble("price")); }//ww w . j a v a 2 s .co m uprs.first(); uprs.updateString("name", "Java"); uprs.updateRow(); uprs.next(); uprs.deleteRow(); uprs.moveToInsertRow(); uprs.updateString("code", "1"); uprs.updateString("name", "Data Structures"); uprs.updateInt("quantity", 1); uprs.updateDouble("price", 5.99); uprs.insertRow(); uprs.beforeFirst(); while (uprs.next()) { System.out.println(uprs.getString("id") + "\t" + uprs.getString("code") + "\t" + uprs.getString("name") + "\t" + uprs.getInt("quantity") + "\t" + uprs.getDouble("price")); } connection.close(); }
From source file:Main.java
public static void main(String[] args) throws Exception { String driver = "sun.jdbc.odbc.JdbcOdbcDriver"; Connection con;//from ww w . jav a 2 s . c o m 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()); } }
From source file:DemoUpdatableResultSet.java
public static void main(String[] args) { ResultSet rs = null; Connection conn = null;/*from w w w . j a va 2 s . c o m*/ PreparedStatement pstmt = null; try { conn = getConnection(); String query = "select id, name, age from employees where age > ?"; pstmt = conn.prepareStatement(query, ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE); pstmt.setInt(1, 20); // set input values rs = pstmt.executeQuery(); // create an updatable ResultSet // update a column value in the current row. rs.absolute(2); // moves the cursor to the 2nd row of rs rs.updateString("name", "newName"); // updates the 'name' column of row 2 to newName rs.updateRow(); // updates the row in the data source // insert column values into the insert row. rs.moveToInsertRow(); // moves cursor to the insert row rs.updateInt(1, 1234); // 1st column id=1234 rs.updateString(2, "newName"); // updates the 2nd column rs.updateInt(3, 99); // updates the 3rd column to 99 rs.insertRow(); rs.moveToCurrentRow(); } catch (Exception e) { e.printStackTrace(); } finally { try { rs.close(); pstmt.close(); conn.close(); } catch (SQLException e) { e.printStackTrace(); } } }
From source file:InsertRowBug.java
public static void main(String args[]) { String url;// ww w . j ava 2s .c o m // url = "jdbc:odbc:SQL Anywhere 5.0 Sample"; // url = "jdbc:oracle:thin:@server:1521:db570"; url = "jdbc:odbc:RainForestDSN"; String driver; //driver = "oracle.jdbc.driver.OracleDriver"; driver = "sun.jdbc.odbc.JdbcOdbcDriver"; String user, pass; user = "student"; pass = "student"; Connection con; Statement stmt; ResultSet uprs; try { Class.forName(driver); } catch (java.lang.ClassNotFoundException e) { System.err.println(e); return; } try { con = DriverManager.getConnection(url, user, pass); stmt = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE); uprs = stmt.executeQuery("SELECT * FROM Music_Recordings"); // 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()); } }
From source file:Transaction.java
public void doWork() { try {/* w w w. j a v a 2s. co m*/ java.util.Date now = new java.util.Date(); connection.setAutoCommit(false); Statement statement = connection.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE); ResultSet rs = statement.executeQuery("SELECT * FROM acc_add WHERE acc_id = 1034055 and ts = 0"); // set old row ts = current time rs.next(); rs.updateTimestamp("ts", new Timestamp(now.getTime())); rs.updateRow(); rs.moveToInsertRow(); rs.updateInt("add_id", rs.getInt("add_id")); rs.updateInt("acc_id", rs.getInt("acc_id")); rs.updateString("name", rs.getString("name")); rs.updateString("address1", "555 East South Street"); rs.updateString("address2", ""); rs.updateString("address3", ""); rs.updateString("city", rs.getString("city")); rs.updateString("state", rs.getString("state")); rs.updateString("zip", rs.getString("zip")); rs.updateTimestamp("ts", new Timestamp(0)); rs.updateTimestamp("act_ts", new Timestamp(now.getTime())); rs.insertRow(); connection.commit(); rs.close(); statement.close(); connection.close(); } catch (Exception e) { try { connection.rollback(); } catch (SQLException error) { } e.printStackTrace(); } }
From source file:net.solarnetwork.node.dao.jdbc.JdbcSettingDao.java
@Override protected void updateBatchRowEntity(BatchOptions options, ResultSet resultSet, int rowCount, Setting entity) throws SQLException { resultSet.updateString(1, entity.getKey()); resultSet.updateString(2, entity.getType()); resultSet.updateString(3, entity.getValue()); resultSet.updateInt(5, SettingFlag.maskForSet(entity.getFlags())); }