Demo ResultSet Oracle : Oracle JDBC : Database SQL JDBC : Java examples (example source code) Organized by topic

Java
C++
PHP


Java  »  Database SQL JDBC   » [  Oracle JDBC  ]  Screenshots 
 



Demo ResultSet Oracle

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

public class DemoResultSetOracle {

  public static Connection getConnection() throws Exception {
    String driver = "oracle.jdbc.driver.OracleDriver";
    String url = "jdbc:oracle:thin:@localhost:1521:databaseName";
    String username = "username";
    String password = "password";

    Class.forName(driver)// load Oracle driver
    Connection conn = DriverManager.getConnection(url, username, password);
    return conn;
  }

  public static void main(String[] args) {
    Connection conn = null;
    Statement stmt = null;
    ResultSet rs = null;
    try {
      conn = getConnection();
      System.out.println("conn=" + conn);
      // prepare query
      String query = "select id, name, age from employees";
      // create a statement
      stmt = conn.createStatement();
      // execute query and return result as a ResultSet
      rs = stmt.executeQuery(query);
      // extract data from the ResultSet
      while (rs.next()) {
        String id = rs.getString(1);
        String name = rs.getString(2);
        int age = rs.getInt(3);
        System.out.println("id=" + id);
        System.out.println("name=" + name);
        System.out.println("age=" + age);
        System.out.println("---------------");
      }
    catch (Exception e) {
      e.printStackTrace();
      System.exit(1);
    finally {
      // release database resources
      try {
        rs.close();
        stmt.close();
        conn.close();
      catch (SQLException e) {
        e.printStackTrace();
      }
    }
  }
}
           
       
Related examples in the same category
1.  Get Object From Oracle Database Using STRUCTHas Download File
2.  Inser BLOG(Picture or Photo) Data Type Into Oracle DatabaseHas Download File
3.  Serialized And Deserialize Object OracleHas Download File
4.  Get Oracle Table NamesHas Download File
5.  Get Parameter MetaData From Oracle JDBC DriverHas Download File
6.  Test Oracle JDBC Driver Installation
7.  Create Employee Table Oracle
8.  Count row in Oracle
9.  Get Column Names From ResultSet for Oracle
10.  All data types for Oracle
11.  Get Column Privileges Oracle
12.  Test OCINet 8 App
13.  Test SSL
14.  Test Data Encryption Integrity
15.  Test DataSource LookUp
16.  OracleDataSource Demo
17.  Register custome type to Oracle
18.  Insert custom type to Oracle
19.  Check JDBC Installation for Oracle
























Home| Contact Us
Copyright 2003 - 07 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.