Create OracleStatement - Java JDBC

Java examples for JDBC:Oracle

Description

Create OracleStatement

Demo Code


import java.util.*;
import java.sql.*;
import oracle.jdbc.*;
class TablerRows/*  www. ja  v  a2 s  .  c o  m*/
{
  OracleConnection oconn;
  OracleStatement ostm;
  OracleResultSet ors;
  String scomm;
  String vusername,vpassword,url;
  Scanner sc = new Scanner(System.in);
  public TablerRows()
  {
    try
    {
       DriverManager.registerDriver(new OracleDriver());
    }
     catch(SQLException ex)
    {
      System.out.println(ex.toString());
    }
    System.out.print("Enter User Name: ");
    vusername = sc.next();
    System.out.print("Enter Password: ");
    vpassword = sc.next();
    url = "jdbc:oracle:thin:@localhost:1521:ORCL";  
    try
    {
      oconn = (OracleConnection)DriverManager.getConnection(url,vusername,vpassword);  
    
      scomm = "select * from DEPT";
                                
      //instantiating the oracle statement
      ostm = (OracleStatement)oconn.createStatement(OracleResultSet.TYPE_SCROLL_SENSITIVE,OracleResultSet.CONCUR_UPDATABLE);  //The object of statement is responsible to execute queries with the database.  
      //instantiating the oracle resultset
                        
      ors=(OracleResultSet)ostm.executeQuery(scomm);
      ors.absolute(3); // this means getting the record of only 3rd row is prited //ors.next() is not calling hare instead use only ors.abssolute(2)
      System.out.println(ors.getString(1)+" "+ors.getString(2)+" "+ors.getString(3));
      System.out.println(ors.getString(1)+"\t"+ors.getString(2)+"\t"+ors.getString(3));
      ors.close();
      ostm.close();
      oconn.close();
    }
    catch(SQLException ex)
    {
      System.out.println(ex.toString());
    }
        }
}
public class REcordRowsDisplay 
{
    public static void main(String args[])
    {
        TablerRows tr=new TablerRows();
    }
}

Related Tutorials