The latest code to connect Oracle is to match the environment variable:
Classpath = .; E: /J2SDK14/LIB/Tools.jar; E: /oracle/ora90/jdbc/lib/classes12.zip
The test-tested computer has been installed in the Oracle client and can be connected with SQLPLUS. / ** This Sample Shows How To list All the name from the Emp table DRIVER. See The Same Program in the * OCI8 Samples Directory to Seeh How To Use The Other Drivers. * /
// you need to import the java.sql package to use jdbcimport java.sql. *;
class Test {public static void main (String args []) throws SQLException {// Load the Oracle JDBC driver DriverManager.registerDriver (new oracle.jdbc.OracleDriver ()); / * try {Class.forName ( "oracle.jdbc. Driver.Oracledriver ");} catch (exception e) {system.out.println (" no driver! ");} * / // connect to the database name at the @ Sign in the connection URL. // You can use Either the full specified sql * net syntax or a short cut // syntax as
IF (Args.Length> 0) URL = args [0]; if (args.length> 1) username = args [1]; if (args.length> 2) Password = args [2]; system.out.println (URL); System.out.Println (username); system.out.println (password); connection conn = drivermanager.getConnection (URL, Username, Password);
// Create a statement statement stmt = conn.createstatement ();
// select the ename column from the Emp Table resultset Rset = stmt.executequery ("Select * from test");