/* * This sample can be used to check the JDBC installation. * Just run it and provide the connect information. It will select * "Hello World" from the database. * * note: jdk1.2 is recommanded. jdk1.1 will also work */ // You need to import the java.sql package to use JDBC import java.sql.*; // We import java.io to be able to read from the command line import java.io.*; class JdbcCheckup { public static void main (String args []) throws SQLException, IOException { // Load the Oracle JDBC driver DriverManager.registerDriver(new oracle.jdbc.OracleDriver()); System.out.println ("Connecting..."); Connection conn = DriverManager.getConnection ("jdbc:oracle:thin:scott/tiger@ws01:1521:ora920"); System.out.println ("connected."); // Create a statement Statement stmt = conn.createStatement (); ResultSet rset = stmt.executeQuery ("select empno,ename,job,mgr,hiredate,sal,comm,deptno from emp"); ResultSetMetaData rsmd = rset.getMetaData(); int numberOfColumns = rsmd.getColumnCount(); while (rset.next ()) { System.out.print (" " + rset.getString(1) + " " + rsmd.getColumnTypeName(1) ); System.out.print (" " + rset.getString(2) + " " + rsmd.getColumnTypeName(2) ); System.out.print (" " + rset.getString(3) + " " + rsmd.getColumnTypeName(3) ); System.out.print (" " + rset.getString(4) + " " + rsmd.getColumnTypeName(4) ); System.out.print (" " + rset.getString(5) + " " + rsmd.getColumnTypeName(5) ); System.out.print (" " + rset.getString(6) + " " + rsmd.getColumnTypeName(6) ); System.out.print (" " + rset.getString(7) + " " + rsmd.getColumnTypeName(7) ); System.out.println (" " + rset.getString(8) + " " + rsmd.getColumnTypeName(8) ); } // close the resultSet rset.close(); // Close the statement stmt.close(); // Close the connection conn.close(); } // end main } // JdbcCheckup.java