Java in Linux connecting to Oracle - java.sql.SQLException: ORA-01017: inva

Hi Java Guru's,

After 8 years with micrsoft technologies its hard to move to something without a GUI and I I have a simple problem which I am not able to resolve.

I am basically totally new to java and linux. I did all my development on windows using eclipse and my application ran fine. It runs on windows without any issues but, when I move my code to a Linux box it just does not work. The applicaition does not even connect to the database.

For simplification I created a simple class which connects to the db and executes a sp that's it; plain and simple. This works fine from windows but, from linux I keep getting

"java.sql.SQLException: ORA-01017: invalid username/password; logon denied"

The username and password is correct and I have tried that with sqlplus in linux box. I think the problem is with some configuration

Here is my environment values:

HOSTNAME=XXXXXX

TERM=vt100

SHELL=/bin/bash

HISTSIZE=1000

SSH_CLIENT=XXX.XX.XX.XX 1792 22

QTDIR=/usr/lib64/qt-3.1

SSH_TTY=/dev/pts/0

USER=sagarwal

LD_LIBRARY_PATH=/dpd/u01/app/oracle/product/9.2/lib:/dpd/u01/app/oracle/product/9.2/jdbc/lib

LS_COLORS=no=00:fi=00:di=01;34:ln=01;36:pi=40;33:so=01;35:bd=40;33;01:cd=40;33;01:or=01;05;37;41:mi=01;05;37;41:ex=01;32:*.cmd=01;32:*.exe=01;32:*.com=01;32:*.btm=01;32:*.bat=01;32:*.sh=01;32:*.csh=01;32:*.tar=01;31:*.tgz=01;31:*.arj=01;31:*.taz=01;31:*.lzh=01;31:*.zip=01;31:*.z=01;31:*.Z=01;31:*.gz=01;31:*.bz2=01;31:*.bz=01;31:*.tz=01;31:*.rpm=01;31:*.cpio=01;31:*.jpg=01;35:*.gif=01;35:*.bmp=01;35:*.xbm=01;35:*.xpm=01;35:*.png=01;35:*.tif=01;35:

ORACLE_SID=dpd

MAIL=/var/spool/mail/sagarwal

PATH=/usr/kerberos/bin:/usr/local/bin:/bin:/usr/bin:/usr/X11R6/bin:/export1/home/nYDS/bin:/dpd/u01/app/oracle/product/9.2/bin:/dpd/u01/app/oracle/product/9.2/jdbc/lib:/dpd/u01/app/oracle/product/9.2/lib:/export1/home/nYDS/PAM/nyds/DBHelper

INPUTRC=/etc/inputrc

PWD=/export1/home/nYDS/PAM

LANG=en_US.UTF-8

LAMHELPFILE=/etc/lam/lam-helpfile

SSH_ASKPASS=/usr/libexec/openssh/gnome-ssh-askpass

SHLVL=1

HOME=/export1/home/nYDS

LOGNAME=sagarwal

CLASSPATH=/dpd/u01/app/oracle/product/9.2/jdbc/lib/classes12.jar:/dpd/u01/app/oracle/product/9.2/rdbms/jlib/xdb.jar:/dpd/u01/app/oracle/product/9.2/sqlj/lib/runtime12.jar:/dpd/u01/app/oracle/product/9.2/sqlj/lib/translator.jar:/dpd/u01/app/oracle/product/9.2/jdbc/lib/classes12_g.jar

SSH_CONNECTION=XXX.XX.XX.XX XXXX XXX.21.33.186 22

LESSOPEN=|/usr/bin/lesspipe.sh %s

ORACLE_HOME=/dpd/u01/app/oracle/product/9.2

G_BROKEN_FILENAMES=1

_=/bin/env

OLDPWD=/export1/home/nYDS/PAM/test

Here is my code

package test;

import java.sql.CallableStatement;

import java.sql.Connection;

import java.sql.DriverManager;

import java.sql.ResultSet;

import java.sql.SQLException;

import oracle.jdbc.OracleTypes;

import oracle.jdbc.driver.OracleDriver;

import oracle.jdbc.pool.OracleDataSource;

import java.sql.*;

public class TestDA {

/**

* @param args

*/

public static void main(String[] args) {

// TODO Auto-generated method stub

System.out.println("started");

showData();

System.out.println("done");

}

public static Connection getConnection()

{

Connection conn = null;

Stringusername = "XXX";

Stringpassword = "XXX123";

Stringdriver_class = "oracle.jdbc.driver.OracleDriver";

StringthinConn= "jdbc:oracle:thin:@xxxxxx.co.xxxx.com:1521:xyz";

System.out.println("in getConnection");

if(conn != null)

return conn ;

try

{

System.out.print("Loading JDBC Driver -> " + driver_class + "\n");

Class.forName (driver_class).newInstance();

System.out.print("Connecting to-> " + thinConn + ", " + username + ", " + password + "\n");

conn = DriverManager.getConnection(thinConn, username, password);

return conn;

}

catch (Exception e)

{

e.printStackTrace();

// throw new SQLException("Error loading JDBC Driver");

}

return conn ;

}

public static void showData()

{

try

{

System.out.println("in showdata");

Connection conn = getConnection();

System.out.println("connection worked");

String sp_Query ;

sp_Query = "{call XXX.XXXXXXXX (?,?)}" ;

CallableStatement sp_stmnt = conn.prepareCall(sp_Query);

sp_stmnt.setString(1, "XXXXXXXX_XXXXXX_XXXXX");

sp_stmnt.registerOutParameter(2, OracleTypes.CURSOR);

System.out.println("calling execute");

int rcdsafctd = sp_stmnt.executeUpdate() ;

System.out.println(rcdsafctd);

ResultSet x = (ResultSet)sp_stmnt.getObject(2);

while(x.next())

{

System.out.println(x.getString(2));

}

}

catch(Exception err)

{

err.printStackTrace();

}

}

}

Please HELP !!!!!!!!!!!!!

[5070 byte] By [skagarwaa] at [2007-11-26 21:05:53]
# 1
Are you sure you have the right uid+pwd for the SID in question?
abillconsla at 2007-7-10 2:39:54 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 2
Is your application running on java 1.2 or 1.3?classes12.jar (or zip) is not 100% compatible to java 1.4 or later version.For later version, you need ojdbc14.jar (or zip).
masuda1967a at 2007-7-10 2:39:54 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 3

> Is your application running on java 1.2 or 1.3?

> classes12.jar (or zip) is not 100% compatible to java

> 1.4 or later version.

> For later version, you need ojdbc14.jar (or zip).

I do not want to hijack this thread ... but if you don't mind, would you have a look at this thread [url http://forum.java.sun.com/thread.jspa?threadID=5145736][/url] and let me know if you think this might be my problem?

abillconsla at 2007-7-10 2:39:54 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 4
abilicons - I do not think this is related to your problem. I am not even able to connect to the database foget about executing a query or stored proc.
skagarwaa at 2007-7-10 2:39:54 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 5

abilicons - thanks for the reply. I have checked the username, password, servername and SID everything more than 10 times. it is correct.

Moreover my username and password is hard coded in the code so if any such value is incorrect it would not run in my windows pc right ?

It works well in windows but does not work in linux - Its breaking my head.

Because the code works I think its some environment setting or some other value I am not setting right.

skagarwaa at 2007-7-10 2:39:54 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 6
masuda - my code is running in java 1.4.If class12.jar is not compatible what class should I use?
skagarwaa at 2007-7-10 2:39:54 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 7

> abilicons - I do not think this is related to your

> problem. I am not even able to connect to the

> database foget about executing a query or stored proc.

No, that reply was to the other poster regarding the use of the ojdbc14.jar

Next, I know this is not the crux of your pblm, but it's a bad idea to hardcode passwords.

Lastly the jar he's suggesting you use is ojdbc14.jar

abillconsla at 2007-7-10 2:39:54 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 8
Hi All,Do I need a MANIFEST file to run a class file directly i.e. no use a jar file but run class directlythe command I use run the code above is "java test.TestDA"
skagarwaa at 2007-7-10 2:39:54 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 9

Thanks for the reply.

I understand its a bad idea to hard code passwords. Its only in my test code which I am using to fix whatever the issues is with connecting to the database.

I added the ojdbc14.jar and now I get this error

Exception in thread "main" java.lang.InternalError: unexpected exception during linking: java.lang.ClassNotFoundException: java.sql.Savepoint

Please help

skagarwaa at 2007-7-10 2:39:54 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 10
Its amazing that such a simple problem in java takes so long to resolve...I am still not able to resolve this....huh.........JAVA
skagarwaa at 2007-7-10 2:39:54 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 11
> > Exception in thread "main" java.lang.InternalError:> unexpected exception during linking:> java.lang.ClassNotFoundException: java.sql.SavepointThat jar doesn't have that class - so you can't use it. Find some other way.
jschella at 2007-7-10 2:39:54 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 12
I added the rt.jar to the classpath and no more get the savepoint exception but still the same old error. java.sql.SQLException: ORA-01017: invalid username/password; logon deniedCome on java people help me? I feel going back to C# and .NET
skagarwaa at 2007-7-10 2:39:54 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 13

> I added the rt.jar to the classpath and no more get

> the savepoint exception but still the same old

> error.

rt.jar from the java JVM.

Then that is NOT a solution.

And what it means is that you are not using the JVM (vendor/version) that you think that you are. All the Sun VMs since at least 1.3 deal with finding the Java API classes themselves.

> java.sql.SQLException: ORA-01017: invalid

> username/password; logon denied

>

> Come on java people help me? I feel going back to C#

> and .NET

I will note simply that if I was getting that error then I would normally assume that it was telling me exactly what the problem was.

At the very least it indicates that the driver is being loaded, that a connection is being made, and that Oracle is returning an error.

jschella at 2007-7-10 2:39:55 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 14
1. Check tnsnames.ora first.2. Try connecting to this database from sqlplus also.3. java.sql.SavePoint is class from JDBC3.0 so you should have proper JDK in your classpath.4. JDBC Driver also has to be in your classpath.I think this will help you.
krunalsa at 2007-7-10 2:39:55 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 15
Thought i had a solution to the problem, but now its occuring again...will updated this if i can get to solve it.
Ravi-Ramakantha at 2007-7-21 18:10:36 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 16
> Thought i had a solution to the problem, but now its> occuring again...will updated this if i can get to> solve it.You do realize that this thread is old now, don't you?
aniseeda at 2007-7-21 18:10:36 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...