473,394 Members | 2,020 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

JDBC weirdness

Hi all!

My problem is very, very silly and stupid, I know, don't blame me for
that please...

When I call my query from SQL*Plus, I get the correct result:

SELECT check_passwd('user', 'password') FROM dual;

CHECK_PASSWD('USER','PASSWORD')
---------------------------------------
1

Now I need to to the same thing from java program, so I wrote the
following test:

Statement stmt = dbm.getConnection().createStatement();
ResultSet rs = stmt.executeQuery("SELECT check_passwd('user','password')
FROM dual");

assertTrue(rs.next());
assertTrue(rs.getInt(1) == 1);

....

However, the second assertion fails! rs.getInt(1) returns "0"!
check_passwd is the function that returns integer, either 0 or 1.
BTW, the same thing happens when I use PreparedStatement and setString()
instead of directly stuffing username and password into the query.

I'm porting the code from PostgreSQL to Oracle, and in Postgres
everything worked perfectly, so ... any ideas?

Thanks in advance!

--
Maxim Slojko
Jul 18 '05 #1
5 3919
What is a return type for check_password? And what would be returned if
instead of getInt(1) you call getString(2)?

Best regards,
Igor.

Maxim пишет:
Hi all!

My problem is very, very silly and stupid, I know, don't blame me for
that please...

When I call my query from SQL*Plus, I get the correct result:

SELECT check_passwd('user', 'password') FROM dual;

CHECK_PASSWD('USER','PASSWORD')
---------------------------------------
1

Now I need to to the same thing from java program, so I wrote the
following test:

Statement stmt = dbm.getConnection().createStatement();
ResultSet rs = stmt.executeQuery("SELECT check_passwd('user','password')
FROM dual");

assertTrue(rs.next());
assertTrue(rs.getInt(1) == 1);

....

However, the second assertion fails! rs.getInt(1) returns "0"!
check_passwd is the function that returns integer, either 0 or 1.
BTW, the same thing happens when I use PreparedStatement and setString()
instead of directly stuffing username and password into the query.

I'm porting the code from PostgreSQL to Oracle, and in Postgres
everything worked perfectly, so ... any ideas?

Thanks in advance!

--
Maxim Slojko

Jul 18 '05 #2
Igor Kolomiyets wrote:
What is a return type for check_password? And what would be returned if
instead of getInt(1) you call getString(2)?
check_password returns integer, either 0 or 1. The function seem to be
fine, except that value is get corrupted somehow, if I use JDBC.
getString(1) returns "0" in that case as well.

Best regards,
Igor.

Maxim пишет:
Hi all!

My problem is very, very silly and stupid, I know, don't blame me for
that please...

When I call my query from SQL*Plus, I get the correct result:

SELECT check_passwd('user', 'password') FROM dual;

CHECK_PASSWD('USER','PASSWORD')
---------------------------------------
1

Now I need to to the same thing from java program, so I wrote the
following test:

Statement stmt = dbm.getConnection().createStatement();
ResultSet rs = stmt.executeQuery("SELECT
check_passwd('user','password') FROM dual");

assertTrue(rs.next());
assertTrue(rs.getInt(1) == 1);

....

However, the second assertion fails! rs.getInt(1) returns "0"!
check_passwd is the function that returns integer, either 0 or 1.
BTW, the same thing happens when I use PreparedStatement and
setString() instead of directly stuffing username and password into
the query.

I'm porting the code from PostgreSQL to Oracle, and in Postgres
everything worked perfectly, so ... any ideas?

Thanks in advance!

--
Maxim Slojko

Jul 18 '05 #3
I'd debug PL/SQL function, JDBC does not seem to be a problem here
unless there is some collision of the datatypes occurs during the call.
Did you try to run this program with JDBC debuggin on?

Maxim пишет:
Igor Kolomiyets wrote:
What is a return type for check_password? And what would be returned
if instead of getInt(1) you call getString(2)?

check_password returns integer, either 0 or 1. The function seem to be
fine, except that value is get corrupted somehow, if I use JDBC.
getString(1) returns "0" in that case as well.

Jul 18 '05 #4
Well, I've got rid of that mistake. Here is the part of explanation, as
I understand it. I would appreciate if you give me the correct one in
return :)

I have a table:
name nvarchar2(20)
passwd nvarchar2(20)
secure number(1)

When I insert something in that table, the BEFORE trigger is fired and
if secure is set to true (or null) password's md5 checksum is stored.
Otherwise plain password is stored (or md5 computed on client side).

My check_passwd function does the same thing. If the account is secure
it computes md5 of supplied password string and compares that value to
the stored one.

The problem appeared due to some chracter conversion issues. The account
was created by simple insert query from SQL*Plus. But was checked from
JDBC. So, when I called check_passwd from SQL*Plus everything was fine,
but when I called it from java it failed. I used only ASCII 7bit
characters in both username and password, so

how this can be?.. I know Oracle has character conversion issues, but
there are only latin letters...

Igor Kolomiyets wrote:
I'd debug PL/SQL function, JDBC does not seem to be a problem here
unless there is some collision of the datatypes occurs during the call.
Did you try to run this program with JDBC debuggin on?

Maxim пишет:
Igor Kolomiyets wrote:
What is a return type for check_password? And what would be returned
if instead of getInt(1) you call getString(2)?


check_password returns integer, either 0 or 1. The function seem to be
fine, except that value is get corrupted somehow, if I use JDBC.
getString(1) returns "0" in that case as well.

Jul 18 '05 #5
What was the reason in using nvarchar2 instead of varchar2? I wouldn't
do this especially when only latin characters are used in the data. I am
almost 100% sure that if you change the data type from nvarchar2 to
varchar2 problem will disappear.

Maxim пишет:
Well, I've got rid of that mistake. Here is the part of explanation, as
I understand it. I would appreciate if you give me the correct one in
return :)

I have a table:
name nvarchar2(20)
passwd nvarchar2(20)
secure number(1)

When I insert something in that table, the BEFORE trigger is fired and
if secure is set to true (or null) password's md5 checksum is stored.
Otherwise plain password is stored (or md5 computed on client side).

My check_passwd function does the same thing. If the account is secure
it computes md5 of supplied password string and compares that value to
the stored one.

The problem appeared due to some chracter conversion issues. The account
was created by simple insert query from SQL*Plus. But was checked from
JDBC. So, when I called check_passwd from SQL*Plus everything was fine,
but when I called it from java it failed. I used only ASCII 7bit
characters in both username and password, so

how this can be?.. I know Oracle has character conversion issues, but
there are only latin letters...

Igor Kolomiyets wrote:
I'd debug PL/SQL function, JDBC does not seem to be a problem here
unless there is some collision of the datatypes occurs during the
call. Did you try to run this program with JDBC debuggin on?

Maxim пишет:
Igor Kolomiyets wrote:

What is a return type for check_password? And what would be returned
if instead of getInt(1) you call getString(2)?


check_password returns integer, either 0 or 1. The function seem to
be fine, except that value is get corrupted somehow, if I use JDBC.
getString(1) returns "0" in that case as well.

Jul 18 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: JShurmatz | last post by:
If anyone can shed some light on this problem I would greatly appreciate it. I am unsuccessfully trying to use a database connnection retrieved from a pool configured using Java System Web...
0
by: Nils Valentin | last post by:
Hi MySQL Fans ;-), Is it possible that the 3.08 series allows to connect to 4.0.14 versions but not to the 4.1 alpha-versions ? I get belows error when tryig to connect from DbVisualizer which...
0
by: Robert Mazur | last post by:
MySQL 5.0 alpha (binary install) on Solaris 9 -or- RedHat 8.0 mysql-connector-java-3.0.8-stable ----------------------- Is there something different going on with JDBC and the alpha version...
1
by: Praveen | last post by:
Hi, I have installed WebSphere Portal on AIX and connected to DB2 on a remote machine, Getting the followin errors when trying to get the values from database thru applications installed on...
5
by: David Thielen | last post by:
Hi; I am creating png files in my ASP .NET app. When I am running under Windows 2003/IIS 6, the file is not given the security permissions it should have. It does not have any permission for...
2
by: bevis | last post by:
I'm new to sql server and mysql but this seems like it should be a pretty straight forward jdbc connection. But I have spent almost 2 days just trying to get a jdbc connection. Please help if you...
3
by: Anoop | last post by:
Is it true that there are no type 4 jdbc drivers to connect to a DB2 server v7.1? The DB2 server is hosted on ACF2 (OS/390). We would be connecting from windows and solaris boxes. If it is true,...
2
by: JYA | last post by:
Hi. I was writing an xmltv parser using python when I faced some weirdness that I couldn't explain. What I'm doing, is read an xml file, create another dom object and copy the element from...
0
by: Jim Kennedy | last post by:
ALL DDL does a commit. Hence Drop Table movies; issues a commit. True you don't issue a commit and the driver does not issue a commit, but the server does for all DDL. That is probably where...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.