rospcc
asked on
Can't connect o Oracle Database
Hi, could anybody advise me on the issue that I got when trying to connect to Oracle? The error message that I got: Exception in thread "main" java.lang.UnsatisfiedLinkE rror: no ocijdbc10 in java.
library.path
I'm using the instantClient. After I set the library path to include the ocijdbc, I got another error: Exception in thread "main" java.lang.UnsatisfiedLinkE rror: t2cGetCharSet
My codes is as follows:
String driver = "oracle.jdbc.driver.Oracle Driver";
Class.forName(driver);
DriverManager.registerDriv er(new oracle.jdbc.driver.OracleD river());
con = DriverManager.getConnectio n("jdbc:or acle:oci:@ DATABASENA ME", USERNAME, PASSWORD);
Is there anything wrong with my codes? Please advise, thanks.
library.path
I'm using the instantClient. After I set the library path to include the ocijdbc, I got another error: Exception in thread "main" java.lang.UnsatisfiedLinkE
My codes is as follows:
String driver = "oracle.jdbc.driver.Oracle
Class.forName(driver);
DriverManager.registerDriv
con = DriverManager.getConnectio
Is there anything wrong with my codes? Please advise, thanks.
looks like the drivers shared lib is not available, perhaps not installed correctly.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
What is the version of Oracle?
Is it 10g?
If yes ask the DBA to ensure static registration of the service by the Listener.
his is a working example:
************************** ********** ********** ********** ***
* Reading from scot/tiger table
************************** ********** ********** ********** **
import java.sql.*;
import oracle.jdbc.pool.OracleDat aSource;
class first {
public static void main (String args []) throws SQLException {
// Create DataSource and connect to the local database
OracleDataSource ods = new OracleDataSource();
ods.setURL("jdbc:oracle:th in:@//oral in3:1521/p hr7b");
ods.setUser("scott");
ods.setPassword("tiger");
Connection conn = ods.getConnection();
// Query the employee names
Statement stmt = conn.createStatement ();
ResultSet rset = stmt.executeQuery ("SELECT ename FROM emp ORDER BY ename");
// Print the name out
while (rset.next ())
System.out.println (rset.getString (1));
//close the result set, statement, and the connection
rset.close();
stmt.close();
conn.close();
}
}
Is it 10g?
If yes ask the DBA to ensure static registration of the service by the Listener.
his is a working example:
**************************
* Reading from scot/tiger table
**************************
import java.sql.*;
import oracle.jdbc.pool.OracleDat
class first {
public static void main (String args []) throws SQLException {
// Create DataSource and connect to the local database
OracleDataSource ods = new OracleDataSource();
ods.setURL("jdbc:oracle:th
ods.setUser("scott");
ods.setPassword("tiger");
Connection conn = ods.getConnection();
// Query the employee names
Statement stmt = conn.createStatement ();
ResultSet rset = stmt.executeQuery ("SELECT ename FROM emp ORDER BY ename");
// Print the name out
while (rset.next ())
System.out.println (rset.getString (1));
//close the result set, statement, and the connection
rset.close();
stmt.close();
conn.close();
}
}
schwertner, based on the error, I don't think we are getting as far as the listener.
Here are relavent snippets of code from a working example that I have that does use instant client.
import java.sql.*;
private Connection dbCon = null;
private String host;
private String user;
private String pass;
// Load the driver
try {
//Class.forName("oracle.jd bc.OracleD river").ne wInstance( );
DriverManager.registerDriv er(new oracle.jdbc.OracleDriver() );
} catch (Exception e) {
throw e;
}
// Connect to the database
try {
dbCon = DriverManager.getConnectio n("jdbc:or acle:oci:" + user + "/" + pass + "@" + host);
} catch(SQLException e) {
throw e;
}
Here are relavent snippets of code from a working example that I have that does use instant client.
import java.sql.*;
private Connection dbCon = null;
private String host;
private String user;
private String pass;
// Load the driver
try {
//Class.forName("oracle.jd
DriverManager.registerDriv
} catch (Exception e) {
throw e;
}
// Connect to the database
try {
dbCon = DriverManager.getConnectio
} catch(SQLException e) {
throw e;
}
johnsone,
every 10g installation needs immediatelly changes in the
listener.ora file. Investigation on every connection problem
begins from Listener services.
It is not a panacea, but helps in 30% of the cases.
every 10g installation needs immediatelly changes in the
listener.ora file. Investigation on every connection problem
begins from Listener services.
It is not a panacea, but helps in 30% of the cases.
Based on the message being loading a unsatisfied symbol in Java, I don't see how it could be anything to do with the listener. The code has not even started if it cannot resolve all the symbols.
OK
>> Class.forName(driver);
>> DriverManager.registerDriv er(new oracle.jdbc.driver.OracleD river());
The call to registerDriver is redundant and not required.
I would also recommend trying out with the thin driver. BTW maybe that you have multiple versions of Java and so the PATH/ CLASSPATH is messed up, which is why it is unable to load the library.
>> DriverManager.registerDriv
The call to registerDriver is redundant and not required.
I would also recommend trying out with the thin driver. BTW maybe that you have multiple versions of Java and so the PATH/ CLASSPATH is messed up, which is why it is unable to load the library.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Mayankeagle, is there any disadvantage in using thin driver?
ASKER
The path of the oci driver actually appear when I executed: System.out.println ( System.getProperty ( "java.library.path" ) ) ;
no downside I'm aware of in using the thin driver
> The path of the oci driver actually appear when I executed: System.out.println ( System.getProperty ( "java.library.path" ) ) ;
was that the directory that contains the oci native lib?
> The path of the oci driver actually appear when I executed: System.out.println ( System.getProperty ( "java.library.path" ) ) ;
was that the directory that contains the oci native lib?