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.

getObject--jConnect doesn't seem to be following JDBC spec

3 posts in JDBC Connect (product renamed to JConnect) Last posting was on 1997-06-18 15:46:57.0Z
Alex Kogon Posted on 1997-06-13 18:30:39.0Z
Message-ID: <33A191CF.1E5E@wizard.bsnet>
Date: Fri, 13 Jun 1997 14:30:39 -0400
From: Alex Kogon <akogon@wizard.bsnet>
X-Mailer: Mozilla 3.01 (X11; U; SunOS 5.5.1 sun4m)
MIME-Version: 1.0
Subject: getObject--jConnect doesn't seem to be following JDBC spec
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Newsgroups: sybase.public.jdbcconnect
Lines: 24
Path: forums-1-dub!forums-master.sybase.com!forums.powersoft.com
Xref: forums-1-dub sybase.public.jdbcconnect:688
Article PK: 252440

Hi, I'm using jConnect to connect to a DB2 server on MVS through the
Sybase Net.Gateway (this could be part of the problem) and am trying to
dynamically determine which tokens are Timestamp objects so I can alter
the way they are output so that I can import them into a Sybase DB by
using the following code:

Object theField=myResultSet.getObject(index);
if(theField instanceof Timestamp)
do special thing
else
do normal thing


According to the JDBC spec, getObject should return Timestamp objects
automatically for Timestamp SQL types. However this didn't work and when
I did a:

System.out.println(myResultSet.getObject(index).getClass().getName())

it said String String String String String forever...

Does jConnect not handle the getObject method correctly or is this a
problem with using the Net.Gateway?

And does anyone have any good ideas for detecting a Timestamp some other
way?

Thanks

alex


Lance Andersen Posted on 1997-06-18 15:46:57.0Z
Message-ID: <33A802F1.1CA8@sybase.com>
Date: Wed, 18 Jun 1997 11:46:57 -0400
From: Lance Andersen <lancea@sybase.com>
X-Mailer: Mozilla 3.01Gold (X11; I; SunOS 5.5.1 sun4m)
MIME-Version: 1.0
To: Alex Kogon <akogon@wizard.bsnet>
Subject: Re: getObject--jConnect doesn't seem to be following JDBC spec
References: <33A191CF.1E5E@wizard.bsnet>
Content-Type: multipart/mixed; boundary="------------630E53784B0E"
Newsgroups: sybase.public.jdbcconnect
Lines: 225
Path: forums-1-dub!forums-master.sybase.com!forums.powersoft.com
Xref: forums-1-dub sybase.public.jdbcconnect:662
Article PK: 252414

Alex,

I have attached a trivial program which demonstrates the use
of getObject by accessing the pubs2 table titles...

This demonstrates that getObject() does return a TimeStamp
object by using instance of

-Lance

Alex Kogon wrote:
>

A Timestamp datatype looks like a sybase datetime datatype...

That is what I would check on your DB2 server.


> Hi, I'm using jConnect to connect to a DB2 server on MVS through the
> Sybase Net.Gateway (this could be part of the problem) and am trying to
> dynamically determine which tokens are Timestamp objects so I can alter
> the way they are output so that I can import them into a Sybase DB by
> using the following code:
>
> Object theField=myResultSet.getObject(index);
> if(theField instanceof Timestamp)
> do special thing
> else
> do normal thing
>
> According to the JDBC spec, getObject should return Timestamp objects
> automatically for Timestamp SQL types. However this didn't work and when
> I did a:
>
> System.out.println(myResultSet.getObject(index).getClass().getName())
>
> it said String String String String String forever...
>
> Does jConnect not handle the getObject method correctly or is this a
> problem with using the Net.Gateway?
>
> And does anyone have any good ideas for detecting a Timestamp some other
> way?
>
> Thanks
>
> alex

--
===============================================================================
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!!!
===============================================================================

//
// setobject class demonstrates how to use the setObject method
//
// setobject may be invoked with the optional parameters:
// -U username
// -P password
// -D debuglibraies
// -S server
//
import java.io.*;
import java.sql.*;
import java.util.*;
import com.sybase.utils.Debug;

class getObject {

static public final int MAXROWS = 5;
static String _user = "sa";
static String _fname = "Anne";
static String _lname = "Ringer";
static String _password = "";
static String _server = "jdbc:sybase:Tds:alder:6689/pubs2";
static String _query =
"select pub_id, pubdate, pubdate from titles";


public static void main (String args[]) {


// Parse the command line

if (!processCommandline(args))
{
System.out.println(
"Syntax:\n" +
"\tBinaryStream [-U <username>] [-P <password>] " +
" [-S <servername>]\n\t\t [-D <debug-class-list>]");
System.exit(1);
}


try {

// Load the Sybase Driver

Class.forName("com.sybase.jdbc.SybDriver");


// Attempt to connect to a driver.

Connection _con = DriverManager.getConnection(_server,
_user, _password);

// If we were unable to connect, an exception
// would have been thrown. So, if we get here,
// we are successfully connected to the URL

// Check for, and display and warnings generated
// by the connect.

checkForWarning (_con.getWarnings ());


// Display Rows

displayRows(_con);


// Close the connection

_con.close();

}
catch (SQLException ex) {

// A SQLException was generated. Catch it and
// display the error information. Note that there
// could be multiple error objects chained
// together

System.out.println ("\n*** SQLException caught ***\n");

while (ex != null) {
System.out.println ("SQLState: " + ex.getSQLState ());
System.out.println ("Message: " + ex.getMessage ());
System.out.println ("Vendor: " + ex.getErrorCode ());
ex = ex.getNextException ();
System.out.println ("");
}
}
catch (java.lang.Exception ex) {

// Got some other type of exception. Dump it.

ex.printStackTrace ();
}
}

//-------------------------------------------------------------------
// checkForWarning
// Checks for and displays warnings. Returns true if a warning
// existed
//-------------------------------------------------------------------

private static boolean checkForWarning (SQLWarning warn) throws SQLException
{
boolean rc = false;

// If a SQLWarning object was given, display the
// warning messages. Note that there could be
// multiple warnings chained together

if (warn != null) {
System.out.println ("\n *** Warning ***\n");
rc = true;
while (warn != null) {
System.out.println ("SQLState: " + warn.getSQLState ());
System.out.println ("Message: " + warn.getMessage ());
System.out.println ("Vendor: " + warn.getErrorCode ());
System.out.println ("");
warn = warn.getNextWarning ();
}
}
return rc;
}

private static void displayRows( Connection con)
throws SQLException
{

Statement stmt = con.createStatement();
System.out.println("Executing: " + _query);


// Do the same thing, but simply specify the SQL Type mapping


ResultSet rs = stmt.executeQuery(_query);
dispResultSet(rs);

// Clear our IN params

rs.close();
stmt.close();
}

static private boolean processCommandline(String args[])
{
//* DONE
String arg;
int errorCount = 0;
for (int i = 0; i < args.length; i++)
{
arg = args[i];
if (arg.regionMatches(0, "-", 0, 1))
{
try
{
switch(arg.charAt(1))
{
case 'D':
i++;
try
{
Debug.debug(true, args[i]);
}
catch (IOException ioe)
{
System.out.println("Error turning on debugging " +
ioe);
}
break;
case 'U':
i++;
_user = args[i];
break;
case 'P':
i++;
_password = args[i];
break;
case 'S':
i++;
_server = args[i];
break;
default:
System.out.println("Invalid command line option: " + arg);
errorCount++;
break;
}
}
catch (ArrayIndexOutOfBoundsException aioobe)
{
System.out.println("missing option argument");
errorCount++;
}
}
else
{
// The syntax has no non "-" arguments
errorCount++;
}
}

return(errorCount == 0);
}

private static void dispResultSet (ResultSet rs) throws SQLException
{
int i;

// Get the ResultSetMetaData. This will be used for
// the column headings

ResultSetMetaData rsmd = rs.getMetaData ();

// Get the number of columns in the result set

int numCols = rsmd.getColumnCount ();

// Display column headings

for (i=1; i<=numCols; i++) {
if (i > 1) System.out.print("\t\t");
System.out.print(rsmd.getColumnLabel(i));
}
System.out.println("");

// Display data, fetching until end of the result set

while (rs.next ()) {

// Loop through each column, getting the
// column data and displaying


System.out.print(rs.getString(1));
Object a = rs.getObject(2);
System.out.print("\t" + a);
if(a instanceof Timestamp)
System.out.print(" is a timestamp");
Timestamp ts = rs.getTimestamp(3);
System.out.print("\t" + ts);
if(ts instanceof Timestamp)
System.out.print(" is a timestamp");
System.out.println("");

// Fetch the next result set row

}
}
}


Alex Kogon Posted on 1997-06-16 19:52:02.0Z
Message-ID: <33A59962.72DA@wizard.bsnet>
Date: Mon, 16 Jun 1997 15:52:02 -0400
From: Alex Kogon <akogon@wizard.bsnet>
X-Mailer: Mozilla 3.01 (X11; U; SunOS 5.5.1 sun4m)
MIME-Version: 1.0
Subject: Re: getObject--jConnect doesn't seem to be following JDBC spec
References: <33A191CF.1E5E@wizard.bsnet>
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Newsgroups: sybase.public.jdbcconnect
Lines: 34
Path: forums-1-dub!forums-master.sybase.com!forums.powersoft.com
Xref: forums-1-dub sybase.public.jdbcconnect:672
Article PK: 252425

No responses yet, thought I'd drop another note cuz I'm dead in the
water without this...

If you need to communicate with me directly my Bear Stearns email is not
accessible from outside the company as I am a consultant. I do have a
private email address however which is:

alko@well.com

Thanks,

alex

Alex Kogon wrote:
>
> Hi, I'm using jConnect to connect to a DB2 server on MVS through the
> Sybase Net.Gateway (this could be part of the problem) and am trying to
> dynamically determine which tokens are Timestamp objects so I can alter
> the way they are output so that I can import them into a Sybase DB by
> using the following code:
>
> Object theField=myResultSet.getObject(index);
> if(theField instanceof Timestamp)
> do special thing
> else
> do normal thing
>
> According to the JDBC spec, getObject should return Timestamp objects
> automatically for Timestamp SQL types. However this didn't work and when
> I did a:
>
> System.out.println(myResultSet.getObject(index).getClass().getName())
>
> it said String String String String String forever...
>
> Does jConnect not handle the getObject method correctly or is this a
> problem with using the Net.Gateway?
>
> And does anyone have any good ideas for detecting a Timestamp some other
> way?
>
> Thanks
>
> alex