java.sql.SQLException: Error loading JDBC Driver
classpath =
C:\WINNT\system32;
C:\j2sdk1.4.2_05\lib;
C:\j2sdk1.4.2_05\jre\lib;
C:\oracle\ora92\jdbc\lib\classes111.jar;
C:\oracle\ora92\jdbc\lib\classes12.jar;.
///start of code
import java.sql.*;
import java.util.*;
import oracle.jdbc.*;
public class OracleConnection {
/*
** +----------------------------------------+
** | Return a JDBC connection appropiately |
** | either inside or outside the database. |
** +----------------------------------------+
*/
public static Connection getConnection() throws SQLException {
String username = "****";
String password = "****";
String driver_class = "oracle.jdbc.OracleDriver";
// +-------------------------------------------------+
// | You can use either of the two URLs to obtain a |
// | default connection. |
// | "jdbc:default:connection:" |
// | "jdbc:oracle:kprb:" |
// +-------------------------------------------------+
//String defaultConn = "jdbc:default:connection:";
String thinConn = "jdbc:oracle:thin:@host:port:db";
Connection conn = null;
try {
System.out.print("Loading JDBC Driver -> " + driver_class + "\n");
Class.forName (driver_class);
System.out.print("Connecting to -> " + thinConn + ", " + username + ", " + password + "\n");
conn = DriverManager.getConnection(thinConn, username, password);
conn.setAutoCommit(false);
return conn;
} catch (Exception e) {
throw new SQLException("Error loading JDBC Driver");
}
} // METHOD: (getConnection)
/*
** +--------------------------------------------------------+
** | Method to determine if we are running in the database. |
** | If oracle.server.version is not null, we are running |
** | in the database. |
** +--------------------------------------------------------+
*/
public static boolean connectedToDatabase() {
String version = System.getProperty("oracle.server.version");
return (version != null && !version.equals(""));
} // METHOD: (connectedToDatabase)
} // CLASS: (OracleConnection)
jdphjp
|