The latest to do a connection to Oracle code, to match the environment variable: classpath=.; E:j2sdk14lib Ools.jar; E:oracleora90jdbclibclasses12.zip
The tested computer is already installed with Oracle clients and can be connected with sqlplus.
/*
* This sample shows the "All" names from the EMP table
*
* It uses the JDBC THIN driver. The same program in the
* Oci8 samples Directory to "to" and "use" the other drivers.
*///You need to import the java.sql package to use JDBC
Import 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
You are must put a database name after the @ sign in the connection URL.
Can use either the fully specified sql*net syntax or a short cut
Syntax as::. The example uses the short cut syntax.
String url = "Jdbc:oracle:thin:@172.28.31.85:1521:yikatong";
String userName = "Scott";
String PassWord = "Tiger"; 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"); Iterate through the result and print the employee names
while (Rset.next ())
System.out.println (rset.getstring (1));
}
}