/* * This sample applet just selects 'Hello World' and the date from the database * * With the JDK-1.0.2 you have to import the package jdbc.sql instead * of java.sql. When you import from jdbc.sql the driver class is in the * package oracle.jdbc.dnlddriver instead of oracle.jdbc.driver and the * connection URL uses dlndthin instead of thin. */ // Import the JDBC classes import jdbc.sql.*; // Import the java classes used in applets import java.awt.*; import java.io.*; import java.util.*; public class JdbcApplet extends java.applet.Applet { // The driver to load static final String driver_class = "oracle.jdbc.dnlddriver.OracleDriver"; // The connect string static final String connect_string = "jdbc:oracle:dnldthin:scott/tiger@dlsun511:1721:dbms733"; // The query we will execute static final String query = "select 'Hello JDBC: ' || sysdate from dual"; // The button to push for executing the query Button execute_button; // The place where to dump the query result TextArea output; // The connection to the database Connection conn; // Create the User Interface public void init () { this.setLayout (new BorderLayout ()); Panel p = new Panel (); p.setLayout (new FlowLayout (FlowLayout.LEFT)); execute_button = new Button ("Hello JDBC"); p.add (execute_button); this.add ("North", p); output = new TextArea (10, 60); this.add ("Center", output); } // Do the work public boolean action (Event ev, Object arg) { if (ev.target == execute_button) { try { // Clear the output area output.setText (null); // See if we need to open the connection to the database if (conn == null) { // Load the JDBC driver output.appendText ("Loading JDBC driver " + driver_class + "\n"); Class.forName (driver_class); // Connect to the databse output.appendText ("Connecting to " + connect_string + "\n"); conn = DriverManager.getConnection (connect_string); output.appendText ("Connected\n"); } // Create a statement Statement stmt = conn.createStatement (); // Execute the query output.appendText ("Executing query " + query + "\n"); ResultSet rset = stmt.executeQuery (query); // Dump the result while (rset.next ()) output.appendText (rset.getString (1) + "\n"); // We're done output.appendText ("done.\n"); } catch (Exception e) { // Oops output.appendText (e.getMessage () + "\n"); } return true; } else return false; } }