Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.server -> How to get started with JDBC?

How to get started with JDBC?

From: Ramon F Herrera <ramon_at_conexus.net>
Date: 24 Jun 2002 03:54:46 -0700
Message-ID: <c9bc36ff.0206240254.bf056cc@posting.google.com>


Oracle 9iR2
Java 1.4
Windows XP
JBuilder 7 SE

I am going to write a Java program which will perform a SQL query to an Oracle server and display the result, and would like to review all my alternatives.

The program will be relatively simple:

This is going to be my first non-trivial Java application. I recently purchased Borland's JBuilder 7 SE. I also downloaded Oracle's JDeveloper, but haven't tried it out yet.

Some of my concerns/questions are:

A tutorial program from the Nutshell J2EE book is included below, that's pretty much what I neeed (plus the GUI stuff, of course).

TIA for your assistance.

Regards,

-Ramon F. Herrera


import java.sql.*;

public class JDBCSample {
  public static void main(java.lang.String[] args) {     try {
      Class.forName("oracle.java");
    }
    catch (ClassNotFoundException e) {

      System.out.println("Unable to load driver class");
      return;

    }
    try {
      Connection con = DriverManager.getConnection("jdbc:odbc:companydb", "", "");
      Statement stmt = con.createStatement();
      ResultSet rs = stmt.executeQuery("SELECT FIRST_NAME FROM EMPLOYEES");
      while (rs.next()) {
        System.out.println(rs.getString("FIRST_NAME"));
      }
      rs.close();
      stmt.close();
      con.close();

    }
    catch (SQLException se){
      System.out.println("SQL Exception: " + se.getMessage());
      se.printStackTrace(System.out);

    }
  }
}
Received on Mon Jun 24 2002 - 05:54:46 CDT

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US