I am not able to connect to oracle 10g from java(j2sdk1.4.2_04) using OCI. I have the basic instantclient10_1 downloaded and I have made my classpath and path point to the instantclient directory. Os used is win2k.
I think I am able to load the driver because
Class.forName ("oracle.jdbc.driver.OracleDriver"); given inside try doesn't get caught.
when I use
DriverManager.getConnection("jdbc:oracle:oci8:scott/tiger@"); I get runtime error(no compile error)
Exception in thread "main" java.lang.UnsatisfiedLinkError: t2cGetCharSet
at oracle.jdbc.driver.T2CConnection.t2cGetCharSet(Native Method)
7) and some more lines.
The same error I get if I use oci instead of oci8 and if I add orcl after @.
I then tried
java -classpath %cp% -Djava.library.path=C:\instantclient MyJavaApp
But I am able to connect using thin client. Please help in setting my oci connection right.
Also if you are installing on windows you might want to be sure and specify the NLS lang variable when you install the database. Dont pick the default, pick the latin character set, the error message you recieved looks like its a character conversion error.
The last thing to check is your tnsnames.ora, sqlnet.ora, and listener.ora
Since 9i connection is made through a service name and not the sid:
A specially formatted description of the destination for a network connection. A connect descriptor contains destination service and network route information.
The destination service is indicated by using its service name for Oracle9i or Oracle8i databases or its Oracle System Identifier (SID) for Oracle release 8.0 databases. The network route provides, at a minimum, the location of the listener through use of a network address.
Here are the basics on using the tools to set that up
As far as the NLS lang variable goes - typically if you are speaking english or some other european latin based derivative, the latin charcter set will work well with what you have installed as the NLS Lang Variable in Oracle... thats the short answer. Here is the long answer:
* Setting the NLS_LANG to the characterset of the database MAY be correct
but IS NOT ALWAYS correct. Please DO NOT assume that NLS_LANG needs to be ALWAYS the same as the database characterset. THIS IS NOT TRUE.
* The characterset defined with the NLS_LANG parameter does NOT CHANGE
your client's characterset, it is used to let Oracle know what characterset
you are USING on the client side, so Oracle can do the proper conversion.
I just realized after the last post, that not everyone is amiliar with the latin character set.
I'm refering to ISO 8859-1 Or WE8ISO8859P1
The default on my pc is
[AMERICAN_AMERICA.WE8MSWIN1252] which may or may not be what I need.
But some how for me the following always does the trick nicely.
The reall killer in going from UTF to another format or vice versa. The 10g OCI client puts to much faith in Microsoft and defaults you to whatever is in windows.
-- Checking your NLS:
From windows, to check the NLS_LANG, you need to open a command prompt and to run sqlplus in command line mode.
First, check if it's set in the environment:
SQL> host echo %NLS_LANG%
If this reports just %NLS_LANG% back, the variable is not set in the
environment. If it's set it reports something like
If NLS_LANG is not set in the enviroment, you should check the value
in the registry:
If you get something like:
unable to open file ".[ENGLISH_UNITED KINGDOM.WE8ISO8859P1]."
the "file name" between the '' is the value of the registry parameter.
(This is NOT an error but just a "trick" to get the NLS_LANG value)
If you get this as result:
unable to open file ".[%NLS_LANG%]."
then the parameter NLS_LANG is also not set in the registry.
Note: the @.[%NLS_LANG%]. "trick" reports the NLS_LANG known by the sqlplus
executable, it will not read the registry itself.
But then you are not sure if the variable is set in the enviroment or in the
registry. That's the reason of checking with the host commando first.
And a sample tnsnames.ora file entry for you:
MYDB = (DESCRIPTION=
( ADDRESS= (PROTOCOL=tcp)(HOST=MYHOST)(PORT=1521) )
( CONNECT_DATA=(SERVICE_NAME=ORCL) )
Sample connection jdbc url
It all works nicely for me. Going live with my first Oracle 10g RAC in production on Sunday. Wish me luck! OCI works fantastically well with the intant client, tomcat and a 10G RAC. TAF and load balancing work nicely with OCI.
Interesting note on the ojdbc14_g.jar. I've verified you can get the same error if you have the wrong JDBC driver for your application. Find the ojdbc*.jar file in your application and replace it with the latest driver from here: