Demo Updatable ResultSet : ResultSet Updatable « Database SQL JDBC « Java

Java
1. 2D Graphics GUI
2. 3D
3. Advanced Graphics
4. Ant
5. Apache Common
6. Chart
7. Collections Data Structure
8. Database SQL JDBC
9. Design Pattern
10. Development Class
11. Email
12. Event
13. File Input Output
14. Game
15. Hibernate
16. J2EE
17. J2ME
18. JDK 6
19. JSP
20. JSTL
21. Language Basics
22. Network Protocol
23. PDF RTF
24. Regular Expressions
25. Security
26. Servlets
27. Spring
28. Swing Components
29. Swing JFC
30. SWT JFace Eclipse
31. Threads
32. Tiny Application
33. Velocity
34. Web Services SOA
35. XML
Microsoft Office Word 2007 Tutorial
Java Tutorial
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
C# / C Sharp
C# / CSharp Tutorial
ASP.Net
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
PHP
Python
SQL Server / T-SQL
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Java » Database SQL JDBC » ResultSet UpdatableScreenshots 
Demo Updatable ResultSet

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class DemoUpdatableResultSet {
  public static Connection getConnection() throws Exception {
    String driver = "oracle.jdbc.driver.OracleDriver";
    String url = "jdbc:oracle:thin:@localhost:1521:databaseName";
    String username = "name";
    String password = "password";
    Class.forName(driver);
    Connection conn = DriverManager.getConnection(url, username, password);
    return conn;
  }

  public static void main(String[] args) {
    ResultSet rs = null;
    Connection conn = null;
    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(120)// 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(11234);                   // 1st column id=1234
      rs.updateString(2"newName");           // updates the 2nd column
      rs.updateInt(399);                     // 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();
      }
    }
  }
}

           
       
Related examples in the same category
1. Delete Row from Updatable ResultSet for MySQL
2. Insert Row to Updatable ResultSet from MySQL
w_w___w.___j_a__v_a__2_s___._co___m_ | Contact Us
Copyright 2003 - 08 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.