/* * This sample shows how to connect and compile a JDBC program * * To run this program you need to: * 1) Copy it to your directory * 2) Fill in your username and password * 3) Compile by typing: * javac -classpath /usr/pubsw/apps/oracle/8.0.4/jdbc/lib/classes111.zip:. SimpleJDBC.java * 4) Run by typing * javac -classpath /usr/pubsw/apps/oracle/8.0.4/jdbc/lib/classes111.zip:. SimpleJDBC * */ // You need to import the java.sql package to use JDBC import java.sql.*; class SimpleJDBC { public static void main (String args []) throws SQLException { // Load the Oracle JDBC driver DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver()); // Connect to the database // You must put a database name after the @ sign in the connection URL. // You can use either the fully specified SQL*net syntax or a short cut // syntax as ::. The example uses the short cut syntax. Connection conn = DriverManager.getConnection ("jdbc:oracle:thin:@oracle-prod:1521:8PRD", "USERNAME", "PASSWORD"); // Create a Statement Statement stmt = conn.createStatement (); // Select the table names from the user_tables ResultSet rset = stmt.executeQuery ("select TABLE_NAME from USER_TABLES"); // Iterate through the result and print out the table names while (rset.next ()) System.out.println (rset.getString (1)); } }