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.

get/setAutoCommit() throws NullPointerException

3 posts in JDBC Connect (product renamed to JConnect) Last posting was on 1997-08-08 20:49:09.0Z
Wayne Irwin Posted on 1997-08-06 21:10:36.0Z
Message-ID: <33E8E84C.3D7B@gwl.ca>
Date: Wed, 06 Aug 1997 16:10:36 -0500
From: Wayne Irwin <wayn@gwl.ca>
Reply-To: wayn@gwl.ca
Organization: Great-West Life
X-Mailer: Mozilla 3.0 (WinNT; U)
MIME-Version: 1.0
Subject: get/setAutoCommit() throws NullPointerException
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Newsgroups: sybase.public.jdbcconnect
Lines: 32
Path: forums-1-dub!forums-master.sybase.com!forums.powersoft.com
Xref: forums-1-dub sybase.public.jdbcconnect:401
Article PK: 252155

I have attached to a SQL Anywhere database successfully and can run
stored procedures ok. When I try to get or set the AutoCommit feature
using the following code:

try {
Connection c = DriverManager.getConnection(getDatabaseURL(), props);
System.out.println("AUTOCOMMIT="+c.getAutoCommit());
} catch (SQLException e) {
throw(new GWLDatabaseException(e.getMessage(), e));
} catch (Exception e) {
e.printStackTrace();
System.exit(0);
}

I get the following exception:

java.lang.NullPointerException
at com.sybase.tds.Tds.getBoolOption(Unknown Source)
at com.sybase.jdbc.SybConnection.getAutoCommit(SybConnection.java)
at ca.gwl.TransactionManager.connect(TransactionManager.java:195)

or the following when I try to set it to false:

java.lang.NullPointerException
at com.sybase.tds.Tds.setOption(Unknown Source)
at com.sybase.jdbc.SybConnection.setAutoCommit(SybConnection.java)
at ca.gwl.TransactionManager.connect(TransactionManager.java:195)

I found the topic on prjdbc_5.htm called "Getting setAutoCommit() to
work with SQL Anywhere" and I am using SQL Anywhere Version 5.5.01.

What's wrong?

Thanks
--
Wayne Irwin
EMail wayn@gwl.ca
Work (204) 946-7999
Fax (204) 946-4567


David Lance Wolf Posted on 1997-08-08 20:49:09.0Z
Message-ID: <33EB8645.68F981C5@sybase.com>
Date: Fri, 08 Aug 1997 13:49:09 -0700
From: David Lance Wolf <dwolf@sybase.com>
Organization: Sybase Professional Services
X-Mailer: Mozilla 4.01 [en] (Win95; U)
MIME-Version: 1.0
Subject: Re: get/setAutoCommit() throws NullPointerException
X-Priority: 3 (Normal)
References: <33E8E84C.3D7B@gwl.ca>
Content-Type: multipart/mixed; boundary="------------E57EE27333F4F4DE6EF5DBD5"
Newsgroups: sybase.public.jdbcconnect
Lines: 129
Path: forums-1-dub!forums-master.sybase.com!forums.powersoft.com
Xref: forums-1-dub sybase.public.jdbcconnect:388
Article PK: 252139

Cross posting to here too..... I should noticed it was a Java problem
and not the OS gateway.


Wayne-


Its a bug in your JAVA code. The getAutoCommit() method of the
Connection Interface returns a primitive boolean rather than a String
object. When the String gets passed it gets a null pointer because its
pointing a String instead of a boolean. Sample code follows below with

this fixed. I dont know why I didnt norice this before over on
jConnect.

Dave Wolf
Sybase Professional Services

------------------------------------Code
Follows----------------------------------------
// Note, this code provided to sybase.public.sqlanywhere.general only
// copyright 1997 Sybase Inc. ALL RIGHTS RESERVED
// David Lance Wolf, Sybase Professional Services
// The real change here Wayne is at the bottom in my main() method
// Where i convert the boolean to a Boolean object, then to a String
object.
// Gotta love Java eh ;-)

import java.sql.*;
import java.io.*;
import java.util.*;

public class TestDB
{

public boolean isAutoCommit(Connection conn)
{
boolean ac = false;
try
{
ac = conn.getAutoCommit();
}
catch(SQLException e)
{
printToScreen(e.toString());
}
return ac;
}

public void printToScreen(String message)
{
System.out.println(message);
}

public Connection getDatabaseConnection(String userid, String
password)
{
Connection conn = null;
try
{
Class.forName("com.sybase.jdbc.SybDriver");
Properties props = new Properties();
props.put("user",userid);
props.put("password",password);
conn =
DriverManager.getConnection("jdbc:sybase:Tds:127.0.0.1:7000", props);
}
catch(SQLException e)
{
printToScreen(e.toString());
}
catch(ClassNotFoundException cne)
{
printToScreen(cne.toString());
}
return conn;
}

public void printDatabaseName(Connection conn)
{

try
{
ResultSet rs = conn.createStatement().executeQuery("Select
db_name()");
rs.next();
String name = rs.getString(1);
printToScreen(name);
}

catch(SQLException e)
{
printToScreen(e.toString());
}

}

public static void main(String args[])
{
TestDB test = new TestDB();
test.printToScreen("Using userid " + args[0] + " and password " +
args[1]);
Connection myConn = test.getDatabaseConnection(args[0], args[1]);
boolean ac = test.isAutoCommit(myConn);
Boolean boolObj = new Boolean(ac);
System.out.println(boolObj.toString()); //Note I use the method
//of the wrapper Boolean
object
//to make it a string!

test.printDatabaseName(myConn);
}
}

Wayne Irwin wrote:

> I have attached to a SQL Anywhere database successfully and can run
> stored procedures ok. When I try to get or set the AutoCommit feature
>
> using the following code:
>
> try {
> Connection c = DriverManager.getConnection(getDatabaseURL(),
> props);
> System.out.println("AUTOCOMMIT="+c.getAutoCommit());
> } catch (SQLException e) {
> throw(new GWLDatabaseException(e.getMessage(), e));
> } catch (Exception e) {
> e.printStackTrace();
> System.exit(0);
> }
>
> I get the following exception:
>
> java.lang.NullPointerException
> at com.sybase.tds.Tds.getBoolOption(Unknown Source)
> at com.sybase.jdbc.SybConnection.getAutoCommit(SybConnection.java)
> at ca.gwl.TransactionManager.connect(TransactionManager.java:195)
>
> or the following when I try to set it to false:
>
> java.lang.NullPointerException
> at com.sybase.tds.Tds.setOption(Unknown Source)
> at com.sybase.jdbc.SybConnection.setAutoCommit(SybConnection.java)
> at ca.gwl.TransactionManager.connect(TransactionManager.java:195)
>
> I found the topic on prjdbc_5.htm called "Getting setAutoCommit() to
> work with SQL Anywhere" and I am using SQL Anywhere Version 5.5.01.
>
> What's wrong?
>
> Thanks
> --
> Wayne Irwin
> EMail wayn@gwl.ca
> Work (204) 946-7999
> Fax (204) 946-4567


Download VCard vcard.vcf


Lance Andersen Posted on 1997-08-07 12:07:13.0Z
Message-ID: <33E9BA71.5095@sybase.com>
Date: Thu, 07 Aug 1997 08:07:13 -0400
From: Lance Andersen <lancea@sybase.com>
X-Mailer: Mozilla 3.01Gold (X11; I; SunOS 5.5.1 sun4m)
MIME-Version: 1.0
To: wayn@gwl.ca
Subject: Re: get/setAutoCommit() throws NullPointerException
References: <33E8E84C.3D7B@gwl.ca>
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Newsgroups: sybase.public.jdbcconnect
Lines: 53
Path: forums-1-dub!forums-master.sybase.com!forums.powersoft.com
Xref: forums-1-dub sybase.public.jdbcconnect:398
Article PK: 252150

Wayne,

Please refer to :
http://www.sybase.com/products/internet/jconnect/docs/prjdbc_5.htm#HEADING5-59


for details. Also, I am not sure whether running the dbugrad
utility would also work. I would suggest checking with
the sql anywhere support team or post to the sql anywhere newsgroup.


-Lance

Wayne Irwin wrote:
>
> I have attached to a SQL Anywhere database successfully and can run
> stored procedures ok. When I try to get or set the AutoCommit feature
> using the following code:
>
> try {
> Connection c = DriverManager.getConnection(getDatabaseURL(), props);
> System.out.println("AUTOCOMMIT="+c.getAutoCommit());
> } catch (SQLException e) {
> throw(new GWLDatabaseException(e.getMessage(), e));
> } catch (Exception e) {
> e.printStackTrace();
> System.exit(0);
> }
>
> I get the following exception:
>
> java.lang.NullPointerException
> at com.sybase.tds.Tds.getBoolOption(Unknown Source)
> at com.sybase.jdbc.SybConnection.getAutoCommit(SybConnection.java)
> at ca.gwl.TransactionManager.connect(TransactionManager.java:195)
>
> or the following when I try to set it to false:
>
> java.lang.NullPointerException
> at com.sybase.tds.Tds.setOption(Unknown Source)
> at com.sybase.jdbc.SybConnection.setAutoCommit(SybConnection.java)
> at ca.gwl.TransactionManager.connect(TransactionManager.java:195)
>
> I found the topic on prjdbc_5.htm called "Getting setAutoCommit() to
> work with SQL Anywhere" and I am using SQL Anywhere Version 5.5.01.
>
> What's wrong?
>
> Thanks
> --
> Wayne Irwin
> EMail wayn@gwl.ca
> Work (204) 946-7999
> Fax (204) 946-4567

--
===============================================================================
Lance J. Andersen Email: lancea@sybase.com
Sybase Technical Support Phone:(617) 564-6336
77 South Bedford Street Fax: (617) 564-6148
Burlington, MA 01803

The Dark Knight Returns!!! Let's Go Penguins!!!
===============================================================================