Sybase NNTP forums - End Of Life (EOL)

The NNTP forums from Sybase - forums.sybase.com - are now closed.

All new questions should be directed to the appropriate forum at the SAP Community Network (SCN).

Individual products have links to the respective forums on SCN, or you can go to SCN and search for your product in the search box (upper right corner) to find your specific developer center.

Zero length string in the sybase table returned as string 'null'

5 posts in JDBC Connect (product renamed to JConnect) Last posting was on 1997-07-30 20:45:57.0Z
Dharani Ramamoorthy Posted on 1997-06-29 18:43:39.0Z
Message-ID: <33B6ACDB.B7179056@mayo.edu>
Date: Sun, 29 Jun 1997 13:43:39 -0500
From: Dharani Ramamoorthy <Ramamoorthy.Dharani@mayo.edu>
Reply-To: Ramamoorthy.Dharani@mayo.edu
Organization: Mayo Foundation
X-Mailer: Mozilla 4.01 [en] (WinNT; I)
MIME-Version: 1.0
Subject: Zero length string in the sybase table returned as string 'null'
X-Priority: 3 (Normal)
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Newsgroups: sybase.public.jdbcconnect
Lines: 42
Path: forums-1-dub!forums-master.sybase.com!forums.powersoft.com
Xref: forums-1-dub sybase.public.jdbcconnect:621
Article PK: 252373

I am executing a stored procedure using escape sequence method. One of
the output parameters is a VARCHAR from the stored procedure. I used the
registerOutParameter call and used the Types.VARCHAR. I used getString
to retrieve the string. I found out, the string of interest to us is a
zero length string in the sybase table. But the getString method returns
a string 'null' instead of a zero length null terminated string. Is this
a bug or am I doing something wrong.
However if the sybase table contains a valid string for the same
column, then everything works fine.
On an another note when I tried to use the length() method ( java api
call on string class ) on the above string it throws an exception. All
the other string methods like equals() or equalsIgnoreCase ends up in
throwing an exception. I can't do anything on the client side to
overcome this problem.

My platform is Windows NT and using NT JConnect product.

Code sample:

CallableStatement cs = con.prepareCall(
"{call " + spName + "(?, ?, ?, ?, ?, ?, ?, ?, ?, ?)}" );

//set the input parameters
...


// set the output parameters
cs.registerOutParameter( 1, Types.VARCHAR );

ResultSet rs = cs.executeQuery();

// I tried all three forms of string creation mentioned below
// still I get s as 'null'
String s = new String();
// String s = "";
// String s = null;

while ( rs.next() )
{
s = rs.getString( 1 );
}

// the following statement s throws an exception
int i = s.length();

Regards,
Dharani Ramamoorthy
Ramamoorthy.Dharani@mayo.edu


David Clegg Posted on 1997-07-30 20:45:57.0Z
Message-ID: <33DFA805.6B24E8AB@sybase.com>
Date: Wed, 30 Jul 1997 13:45:57 -0700
From: David Clegg <davec@sybase.com>
X-Mailer: Mozilla 3.01 (X11; I; Linux 1.2.13 i586)
MIME-Version: 1.0
To: Ramamoorthy.Dharani@mayo.edu
Subject: Re: Zero length string in the sybase table returned as string 'null'
References: <33B6ACDB.B7179056@mayo.edu>
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Newsgroups: sybase.public.jdbcconnect
Lines: 43
Path: forums-1-dub!forums-master.sybase.com!forums.powersoft.com
Xref: forums-1-dub sybase.public.jdbcconnect:440
Article PK: 252196

Sybase Server does not allow you to store a 0-length string in a
VARCHAR column - the server uses an unsigned-byte to represent
the length of a VARCHAR value, and when that length is 0 it explicitly
means that the column is NULL.

In your code, you can use
String s = cs.getString(1);
if (s != null)
{ // whatever you were going to do }

As mentioned in another post, there is also a wasNull() method you
can use to see if the last column you got was SQL-NULL, but that is
mainly used for getInt(), getShort(), getFloat(), etc. functions which
return primitive types. Those methods return a '0' value since
primitive types cannot be null -- the wasNull() method is there only
to distinguish NULL from 0 for these types.

dave

Dharani Ramamoorthy wrote:
>
> I am executing a stored procedure using escape sequence method. One of
> the output parameters is a VARCHAR from the stored procedure. I used the
> registerOutParameter call and used the Types.VARCHAR. I used getString
> to retrieve the string. I found out, the string of interest to us is a
> zero length string in the sybase table. But the getString method returns
> a string 'null' instead of a zero length null terminated string. Is this
> a bug or am I doing something wrong.
> However if the sybase table contains a valid string for the same
> column, then everything works fine.
> On an another note when I tried to use the length() method ( java api
> call on string class ) on the above string it throws an exception. All
> the other string methods like equals() or equalsIgnoreCase ends up in
> throwing an exception. I can't do anything on the client side to
> overcome this problem.
>


Andrew Schonberger Posted on 1997-07-05 23:37:39.0Z
From: Andrew.Schonberger@btal.com.au (Andrew Schonberger)
Subject: Re: Zero length string in the sybase table returned as string 'null'
Date: Sat, 05 Jul 1997 23:37:39 GMT
Message-ID: <33bed9cf.12151482@forums.sybase.com>
References: <33B6ACDB.B7179056@mayo.edu>
X-Newsreader: Forte Free Agent 1.1/32.230
Newsgroups: sybase.public.jdbcconnect
Lines: 61
Path: forums-1-dub!forums-master.sybase.com!forums.powersoft.com
Xref: forums-1-dub sybase.public.jdbcconnect:587
Article PK: 252338

On Sun, 29 Jun 1997 13:43:39 -0500, Dharani Ramamoorthy

<Ramamoorthy.Dharani@mayo.edu> wrote:

>I am executing a stored procedure using escape sequence method. One of
>the output parameters is a VARCHAR from the stored procedure. I used the
>registerOutParameter call and used the Types.VARCHAR. I used getString
>to retrieve the string. I found out, the string of interest to us is a
>zero length string in the sybase table. But the getString method returns
>a string 'null' instead of a zero length null terminated string. Is this
>a bug or am I doing something wrong.
> However if the sybase table contains a valid string for the same
>column, then everything works fine.
>On an another note when I tried to use the length() method ( java api
>call on string class ) on the above string it throws an exception. All
>the other string methods like equals() or equalsIgnoreCase ends up in
>throwing an exception. I can't do anything on the client side to
>overcome this problem.
>
>My platform is Windows NT and using NT JConnect product.
>
>Code sample:
>
>CallableStatement cs = con.prepareCall(
> "{call " + spName + "(?, ?, ?, ?, ?, ?, ?, ?, ?, ?)}" );
>
> //set the input parameters
>...
>
>
> // set the output parameters
> cs.registerOutParameter( 1, Types.VARCHAR );
>
> ResultSet rs = cs.executeQuery();
>
> // I tried all three forms of string creation mentioned below
> // still I get s as 'null'
> String s = new String();
> // String s = "";
> // String s = null;
>
> while ( rs.next() )
> {
> s = rs.getString( 1 );
> }
>
> // the following statement s throws an exception
> int i = s.length();
>
>Regards,
>Dharani Ramamoorthy
>Ramamoorthy.Dharani@mayo.edu
>
>

I'm not a Sybase employee, just a person reading this forum.
As far as I can remember, there is a function called wasNull()
or something like that. If you call this function after getString(),
then it returns True if the parameter you just got was NULL in
a Sybase sense, and returns FALSE if the string is empty.

This way, you can distinguish an empty string from a
Sybase NULL. In both cases, the java object is 'null'.

Obviously, if an object reference is null in Java, then you
cannot call any of the methods of that object. That's why
equals() fails.

Andrew Schonberger

andrew_sc@compuserve.com


Lance Andersen Posted on 1997-07-03 12:26:30.0Z
Message-ID: <33BB9A76.4AF9@sybase.com>
Date: Thu, 03 Jul 1997 08:26:30 -0400
From: Lance Andersen <lancea@sybase.com>
Organization: Product Support Engineering
X-Mailer: Mozilla 3.01Gold (Win95; I)
MIME-Version: 1.0
Subject: Re: Zero length string in the sybase table returned as string 'null'
References: <33B6ACDB.B7179056@mayo.edu>
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Newsgroups: sybase.public.jdbcconnect
Lines: 50
Path: forums-1-dub!forums-master.sybase.com!forums.powersoft.com
Xref: forums-1-dub sybase.public.jdbcconnect:595
Article PK: 252347

Hi,

To process OUT parameters you need to use CallableStatement.getXXX
methods. Your example is using ResultSet.getXXX.

Also remember to always process all ResultSets prior to accessing OUT
param values.

-Lance

Dharani Ramamoorthy wrote:
>
> I am executing a stored procedure using escape sequence method. One of
> the output parameters is a VARCHAR from the stored procedure. I used the
> registerOutParameter call and used the Types.VARCHAR. I used getString
> to retrieve the string. I found out, the string of interest to us is a
> zero length string in the sybase table. But the getString method returns
> a string 'null' instead of a zero length null terminated string. Is this
> a bug or am I doing something wrong.
> However if the sybase table contains a valid string for the same
> column, then everything works fine.
> On an another note when I tried to use the length() method ( java api
> call on string class ) on the above string it throws an exception. All
> the other string methods like equals() or equalsIgnoreCase ends up in
> throwing an exception. I can't do anything on the client side to
> overcome this problem.
>
> My platform is Windows NT and using NT JConnect product.
>
> Code sample:
>
> CallableStatement cs = con.prepareCall(
> "{call " + spName + "(?, ?, ?, ?, ?, ?, ?, ?, ?, ?)}" );
>
> //set the input parameters
> ...
>
> // set the output parameters
> cs.registerOutParameter( 1, Types.VARCHAR );
>
> ResultSet rs = cs.executeQuery();
>
> // I tried all three forms of string creation mentioned below
> // still I get s as 'null'
> String s = new String();
> // String s = "";
> // String s = null;
>
> while ( rs.next() )
> {
> s = rs.getString( 1 );
> }
>
> // the following statement s throws an exception
> int i = s.length();
>
> Regards,
> Dharani Ramamoorthy
> Ramamoorthy.Dharani@mayo.edu

H


Lance Andersen Posted on 1997-07-03 12:24:15.0Z
Message-ID: <33BB99EF.39F@sybase.com>
Date: Thu, 03 Jul 1997 08:24:15 -0400
From: Lance Andersen <lancea@sybase.com>
Organization: Product Support Engineering
X-Mailer: Mozilla 3.01Gold (Win95; I)
MIME-Version: 1.0
Subject: Re: Zero length string in the sybase table returned as string 'null'
References: <33B6ACDB.B7179056@mayo.edu>
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Newsgroups: sybase.public.jdbcconnect
Lines: 50
Path: forums-1-dub!forums-master.sybase.com!forums.powersoft.com
Xref: forums-1-dub sybase.public.jdbcconnect:596
Article PK: 252348

Hi,

To process OUT parameters results, you need to use
CallableStatement.getXXX methods. Your example below is using the
ResultSet.getXXX method.

Also please remember to process all resul
Regards,

-LanceDharani Ramamoorthy wrote:
>
> I am executing a stored procedure using escape sequence method. One of
> the output parameters is a VARCHAR from the stored procedure. I used the
> registerOutParameter call and used the Types.VARCHAR. I used getString
> to retrieve the string. I found out, the string of interest to us is a
> zero length string in the sybase table. But the getString method returns
> a string 'null' instead of a zero length null terminated string. Is this
> a bug or am I doing something wrong.
> However if the sybase table contains a valid string for the same
> column, then everything works fine.
> On an another note when I tried to use the length() method ( java api
> call on string class ) on the above string it throws an exception. All
> the other string methods like equals() or equalsIgnoreCase ends up in
> throwing an exception. I can't do anything on the client side to
> overcome this problem.
>
> My platform is Windows NT and using NT JConnect product.
>
> Code sample:
>
> CallableStatement cs = con.prepareCall(
> "{call " + spName + "(?, ?, ?, ?, ?, ?, ?, ?, ?, ?)}" );
>
> //set the input parameters
> ...
>
> // set the output parameters
> cs.registerOutParameter( 1, Types.VARCHAR );
>
> ResultSet rs = cs.executeQuery();
>
> // I tried all three forms of string creation mentioned below
> // still I get s as 'null'
> String s = new String();
> // String s = "";
> // String s = null;
>
> while ( rs.next() )
> {
> s = rs.getString( 1 );
> }
>
> // the following statement s throws an exception
> int i = s.length();
>
> Regards,
> Dharani Ramamoorthy
> Ramamoorthy.Dharani@mayo.edu