JDBC Reverse Select : SQL Select Query : Database SQL JDBC : Java examples (example source code) Organized by topic

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. JSP
19. JSTL
20. Language Basics
21. Network Protocol
22. PDF RTF
23. Regular Expressions
24. Security
25. Servlets
26. Spring
27. Swing Components
28. Swing JFC
29. SWT JFace Eclipse
30. Threads
31. Tiny Application
32. Velocity
33. XML
Java Tutorial
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 » SQL Select QueryScreenshots 
JDBC Reverse Select

/*

Database Programming with JDBC and Java, Second Edition
By George Reese
ISBN: 1-56592-616-1

Publisher: O'Reilly

*/


import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Properties;

/**
 * Example 3.5.
 */
public class ReverseSelect {
  public static void main(String argv[]) {
    Connection con = null;

    try {
      String url = "jdbc:msql://carthage.imaginary.com/ora";
      String driver = "com.imaginary.sql.msql.MsqlDriver";
      Properties p = new Properties();
      Statement stmt;
      ResultSet rs;

      p.put("user""borg");
      Class.forName(driver).newInstance();
      con = DriverManager.getConnection(url, "borg""");
      stmt = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
          ResultSet.CONCUR_READ_ONLY);
      rs = stmt.executeQuery("SELECT * from test ORDER BY test_id");
      // as a new ResultSet, rs is currently positioned
      // before the first row
      System.out.println("Got results:");
      // position rs after the last row
      rs.afterLast();
      while (rs.previous()) {
        int a = rs.getInt("test_id");
        String str = rs.getString("test_val");

        System.out.print("\ttest_id= " + a);
        System.out.println("/str= '" + str + "'");
      }
      System.out.println("Done.");
    catch (Exception e) {
      e.printStackTrace();
    finally {
      if (con != null) {
        try {
          con.close();
        catch (SQLException e) {
          e.printStackTrace();
        }
      }
    }
  }
}

           
       
Related examples in the same category
1. JDBC select
2. A trivial example of a database query performed with JDBC
3. Load MYSQL JDBC Driver and run the query
4. Oracle JDBC: select
5. Join two tables
Home | Contact Us
Copyright 2003 - 07 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.