Solved

Can't connect o Oracle Database

Posted on 2007-03-19
14
5,996 Views
Last Modified: 2013-12-29
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.UnsatisfiedLinkError: 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.UnsatisfiedLinkError: t2cGetCharSet

My codes is as follows:
String driver = "oracle.jdbc.driver.OracleDriver";
Class.forName(driver);
DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
con = DriverManager.getConnection("jdbc:oracle:oci:@DATABASENAME", USERNAME, PASSWORD);

Is there anything wrong with my codes? Please advise, thanks.
0
Comment
Question by:rospcc
  • 3
  • 3
  • 2
  • +2
14 Comments
 
LVL 92

Expert Comment

by:objects
ID: 18746725
looks like the drivers shared lib is not available, perhaps not installed correctly.
0
 
LVL 92

Accepted Solution

by:
objects earned 250 total points
ID: 18746734
0
 
LVL 47

Expert Comment

by:schwertner
ID: 18747201
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.OracleDataSource;

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:thin:@//oralin3:1521/phr7b");
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();
}
}
0
 
LVL 34

Expert Comment

by:johnsone
ID: 18747601
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.jdbc.OracleDriver").newInstance();
          DriverManager.registerDriver(new oracle.jdbc.OracleDriver());
      } catch (Exception e) {
          throw e;
      }

      // Connect to the database
      try {
          dbCon = DriverManager.getConnection("jdbc:oracle:oci:"  + user + "/" + pass + "@" + host);
                  
      } catch(SQLException e) {
          throw e;
      }
0
 
LVL 47

Expert Comment

by:schwertner
ID: 18748101
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.
0
 
LVL 34

Expert Comment

by:johnsone
ID: 18748406
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.
0
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
LVL 47

Expert Comment

by:schwertner
ID: 18748561
OK
0
 
LVL 30

Expert Comment

by:Mayank S
ID: 18750298
>> Class.forName(driver);
>> DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());

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.
0
 
LVL 30

Assisted Solution

by:Mayank S
Mayank S earned 250 total points
ID: 18750925
Any library which has to be loaded should be contained in "java.library.path". Try printing:

System.out.println ( System.getProperty ( "java.library.path" ) ) ;

and see if it contains the directory containing that library.
0
 

Author Comment

by:rospcc
ID: 18754045
Mayankeagle, is there any disadvantage in using thin driver?
0
 

Author Comment

by:rospcc
ID: 18754047
The path of the oci driver actually appear when I executed: System.out.println ( System.getProperty ( "java.library.path" ) ) ;
0
 
LVL 92

Expert Comment

by:objects
ID: 18754052
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?
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
eclipse argument 14 53
Fastest way to replace data in Oracle 5 51
1 FROM DUAL wont work with additional columns ?? 4 26
MULTIPLE DATE QUERY 15 52
Configuring and using Oracle Database Gateway for ODBC Introduction First, a brief summary of what a Database Gateway is.  A Gateway is a set of driver agents and configurations that allow an Oracle database to communicate with other platforms…
This post first appeared at Oracleinaction  (http://oracleinaction.com/undo-and-redo-in-oracle/)by Anju Garg (Myself). I  will demonstrate that undo for DML’s is stored both in undo tablespace and online redo logs. Then, we will analyze the reaso…
This video shows how to Export data from an Oracle database using the Datapump Export Utility.  The corresponding Datapump Import utility is also discussed and demonstrated.
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now