/* * This sample applet list all entries from the table dogs in the database * ALSO asks user for privilege to connect via sockets to non-web-server machine */ // Import the JDBC classes import java.sql.*; // Import the java classes used in applets import java.awt.*; import java.io.*; import java.util.*; //NEW need package for netscape specific security import netscape.security.*; public class TestAppletSecurity extends java.applet.Applet { // The driver to load static final String driver_class = "oracle.jdbc.driver.OracleDriver"; // The connect string static final String connect_string = "jdbc:oracle:thin:lgrewe/lgrewe@134.154.11.126:1521:labdb"; // This is the kind of string you woudl use if going through the // Oracle 8 connection manager which lets you run the database on a // different host than the Web Server. See the on-line documentation // for more information. //where newton.sci.csuhayward.edu at port 1610 has the Net8 Connection Manager installed //AND 134.154.11.126 (bosack) has the Database Server @ port 1521 // static final String connect_string = "jdbc:oracle:thin:lgrewe/lgrewe@(description=(address_list=(address=(protocol=tcp)(host=newton.sci.csuhayward.edu)(port=1610))(address=(protocol=tcp)(host=134.154.11.126)(port=1521)))(source_route=yes)(connect_data=(sid=labdb)))"; // The query we will execute static final String query = "select * from dogs"; // 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) { //NEW Ask for permission for "socket connection privileges" // to access DB Server not equivalent to web-server try { PrivilegeManager.enablePrivilege("UniversalConnect"); /* PrivilegeManager.enablePrivilege("UniversalFileAccess"); String home = System.getProperty("java.home"); PrivilegeManager.revertPrivilege("UniversalFileAccess"); System.out.println("java.home: " + home); */ } catch (ForbiddenTargetException e) { System.err.println("User denied access to other server"); } // Load the JDBC driver output.appendText ("Loading JDBC driver " + driver_class + "\n"); Class.forName (driver_class); // Connect to the databse output.appendText ("Connecting to jdbc:oracle:thin:@134.154.11.126:1521:labdb\n"); conn = DriverManager.getConnection ("jdbc:oracle:thin:@134.154.11.126:1521:labdb", "lgrewe", "lgrewe"); 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 ()) { for(int i=1; i