jConnect Sample Programs

This directory contains the source code for several sample programs that demonstrate how to use various JDBC classes and methods with jConnect. All of these samples are compatible with SQL Server.

NOTE: These samples are intended for demonstration purposes only.

Compiling the Samples

Running the Samples

As an Application

Sample Driver Interface

Executable Samples

The following is a list of the executable samples that are available, with a description of each program.
AsciiStream.java Demonstrates the setAsciiStream and getAsciiStream methods.
AutoCommit.java Demonstrates the getAutoCommit, setAutoCommit, rollback, and commit methods.
BinaryStream.java Demonstrates the setBinaryStream and getBinaryStream methods.
Callable.java Demonstrates how a callable statement is executed, including creating stored procedures. See pubs2_sql.sql to execute on your local server. 
DBMetadata.java Demonstrates the DatabaseMetaData methods. Displays output for all of the DatabaseMetaData methods. Use the -M option to specify a specific method.
DebugExample.java Demonstrates how to specify the Debug Properties sybDebug and sybLogStream.
DriverMgr.java Demonstrates how to use the DriverManager class.
Encrypt.java Encrypt class demonstrates how to use the custom socket feature with jConnect using SSL implementation of javax.net.SSLSocket, and javax.net.SSLSocketFactory. See MySSLSocketFactory.java on how this is done. 

NOTE: jConnect with SSL is for Java client applications that need to establish a secure connection with a server. Currently, no Sybase servers support SSL. Support is planned for future Sybase products. An applet that needs a secure connection should use an HTTPS gateway. 

Escape.java Demonstrates the jConnect Escape syntax
Execute.java Demonstrates the execute method
ExecuteQuery.java Demonstrates the executeQuery method
ExecuteUpdate.java Demonstrates the executeUpdate method
GetObject.java Demonstrates the GetObject method. This example checks to see if a timestamp datatype is returned
HandleObject.java

 
Demonstrates how to insert, update and select objects from a backend that supports native serialization of Java objects (ASA 6.0.0.1, ASE 12.0, or higher) The Address object needs to be installed on the server. This can not run as an applet right now.
Isql.java

 
A sample utility, that allows the user to enter command line options, to access a sql server, much like you would using isql. Run 
IsqlApp.java

 
A sample utility, that allows the user to enter command line options, to access a sql server, much like you would using isql. You cannot run this from an applet, this is command line only. java IsqlApp [options]
JdbcDriver.java Demonstrates how to use the jdbc.drivers' system properties to load the jConnect driver. Can't run as applet. 
LoaderSample.java Demonstrates how to use the Dynamic Class Loading using the CLASS_LOADER property. This sample only works with ASE 12 and ASA 6 and above. Please refer to the comments in the source of LoaderSample for what needs to be installed on the backend database. 
MessageHandler.java

 
Demonstrates how to use message callbacks as you can in CTLIB. 
MyCallable.java

 
Demonstrates how to use a CallableStatement.  See pubs2_sql.sql to execute on your local server. 
MyConnection.java
Demonstrates how to use the Connection methods. 
MyDriver.java

 
Demonstrates the Driver and DriverPropertyInfo classes. 
MyPrepare.java

 
Demonstrates how to use a PreparedStatement.
MyResultSet.java

 
Demonstrates how to use a ResultSet object.
NameBindRPC.java

 
Demonstrates how to execute a stored procedure using name binding.  See pubs2_sql.sql to execute on your local server. 
Ping.java Sample utility that demonstrates the ability to "ping" - check if a machine is alive by successfully connecting to it. Connects to the Sybase Server outside our firewall.
PreLoadSample.java Demonstrates how to use the Dynamic Class Loading using the CLASS_LOADER and PRELOAD_JARS properties. This sample only works with ASE 12 and ASA 6 and above. Please refer to the comments in the source of LoaderSample for what needs to be installed on the backend database. 
Prepare.java

 
Demonstrates how a prepared statement is handled. 
PrintExample.java

 
Demonstrates how to process the T-SQL print command.  See pubs2_sql.sql to execute on your local server. 
RSMetadata.java Demonstrates how to use ResultSetMetaData methods. 
Raiserror.java Demonstrates how to process raiserror messages that are raised as SQLExceptions. See pubs2_sql.sql to execute on your local server. 
ReadCursor.java

 
Demonstrates how to use a read only cursor.
ScrollableSample.java

 
Demonstrates the use of the ExtendedResultSet class which is used to provide support for Scrollable cursors.
SetObject.java

 
Demonstrates the setObject method.
EventHandler.java Demonstrates the use of the SybEventHandler class to create an event handler for a Connection to a Sybase Open Server. ( This sample registers a stored procedure out on the server to prepare to listen for and handle events). Can't run as applet. 
SimpleSelect.java

 
Describes how to create and execute a simple select statement. 
SybEedInfo.java

 
Demonstrates how to use the SybSQLException class which extends SQLException and the SybSQLWarning class which extends SQLWarnings. 
SybTimestamp.java

 
Demonstrates how to process a Sybase timestamp datatype via an Output Parameter of a CallableStatement   See pubs2_sql.sql to execute on your local server. 
TextPointers.java

 
A sample, that shows how to use the TextPointer class to insert blobs the fast way. It's MUCH faster than using BinaryStream. And the usage is pretty easy. Caution: This sample does NOT run against SQL Anywhere! 
UnicodeStream.java

 
Demonstrates the setUnicodeStream and getUnicodeStream methods. 
UpdateCursor.java

 
Demonstrates how to use multiple cursors at the same time. 
Validate.java

 
A sample utility that allows you to validate that your jdbc driver is working correctly by displaying driver version information and establishing a connection to a Sybase server.
Version.java

 
A sample utiltity that displays the driver's version string, as well as if the driver contains an expiration date. 
 Support Classes


The following classes are support classes for the executable samples; they are not intended to be executed. You must compile these classes in order to run the executable samples.
 
 
Address.java This class needs to be compiled, jar'ed und installed on a backend that supports native serialization of Java objects in the server (ASE 6.0.0.1, ASE 12.0, or higher). This is needed by HandleObject.java. Look into its header section or its javadocs to get more information.
AsciiToUniFileInputStream.java Assists in reading a byte stream and converting it so that it appears to be a unicode stream. This is needed by UnicodeStream.java as a support class and is not intended to be run.
CommandLine.java Assists in reading and parsing the command line options within a main method of a class. This is especially useful for inserting debugging, user, password, and server properties..
DataRow.java Stores a row of data values.
DataRowCache.java An interface for manipulating a cache of DataRow objects.
 Used internally by the Query and ExtendedResultSet objects.
Employee.java This class needs to be compiled and placed in the same jar that contains the Person interface. It then needs to be installed on the backend that supports native serialization of Java objects in the server (ASE 6.0.0.1, ASE 12.0, or higher). This is needed by LoaderSample.java and PreLoadSample.java. Refer to the installation instructions in the comments in LoaderSample.java or PreLoadSample.java.
ExtendedResultSet.java A class which extends ResultSet in order to provide a means to utilize Scrollable ResultSets using JDBC 1.0.x.
MySSLSocketFactory.java Creates a secure Socket and demonstrates how to set cipher suites based on connection properties. SSL is needed for encryption, authentication and message verification. When jConnect is used with SSL, all TDS communication sent to the server is encrypted. See Encrypt.java for a sample on how to execute/use this SybSocketFactory implementation. 

NOTE: jConnect with SSL is for Java client applications that need to establish a secure connection with a server. Currently, no Sybase servers support SSL. Support is planned for future Sybase products. An applet that needs a secure connection should use an HTTPS gateway. 

COMPILE NOTE: You will not be able to recompile this class if javax.net.ssl package is not in your CLASSPATH. To obtain this, you must go to the Sun web site and download them via the JavaWebServer. 

Person.java This interface needs to be compiled and placed in the same jar that contains Employee. It then needs to be installed on the backend that supports native serialization of Java objects in the server (ASE 6.0.0.1, ASE 12.0, or higher). This is needed by LoaderSample.java and PreLoadSample.java. Refer to the installation instructions in the comments in LoaderSample.java or PreLoadSample.java.
Sample.java An abstract class subclassed by all of sample programs within the JDBC_HOME/sample2/ dir It contains various methods used by all samples, as well and the abstract sampleCode method, which is defined within each sample in order to implement specifically what the sample is trying to demonstrate. This enables the code to be clear, and not burdening the user with setup.
ScrollableResultSet.java An interface used to define the Scrollable ResultSet methods available for use by ExtendedResultSet. ExtendedResultSet implements ScrollableResultSet.
SQLValue.java The purpose of this class is to provide a means of storing column values of a result set, and to hide the data conversion routines from the perspective of the ResultSet interface.<p> 
SunIoConverter.java This is an impure (but efficient) implementation of CharsetConverter which relies on the sun.io package, especially classes ByteToCharConverter and CharToByteConverter. It may be used with jConnect instead of the 100% Pure Java implementation by setting the CHARSET_CONVERTER_CLASS connection property to sample2.SunIoConverter

NOTE: This class uses classes from the package sun.io, which may not be present in all Java VMs. JavaSoft is free to change anything in the sun.io package in future releases. If you decide to use this converter or any derivative of it in your application for performance reasons, you may need to make code changes in the future if sun.io changes.

SybSample.java Sample driver, allowing the user to run any of the sybase samples except IsqlApp, and IsqlApplet from the command line or from an applet and launch a GUI application that runs a sample, displays the output, and gives the option to open and run another sample. 
SybSampleApplet.java Creates an applet, which consists of a run button. When selected it instantiates the SybSample class, which is a sample driver application 

Pubs2_sql.sql Script


If you would like to execute the samples using your local server, you must include the pubs2_sql.sql script on your server. This script, contained in this sample directory, is an extension to the pubs2 database which allows you to run some samples that access stored procedures( Callable.java, MyCallable.java, Raiserror.java, and SybTimestamp). We have pre-loaded this script onto our demo server; therefore you should be able to execute all the samples from this applet successfully.
 

SQL Anywhere-compatible Samples


The following samples are compatable with SQL Anywhere. However, in order to run them you need to install the pubs2_any.sql script onto your SQL Anywhere server. This file is available in the jConnect sample directory from where you are viewing this file, and it is intended to create a pubs2 database on your sql anywhere server.

Only the samples listed below are SQL Anywhere-compatible. The other samples are not entirely compatible because they include features that may not be supported, or do not have the same column names for systables. We decided to only provide samples that demonstrate the full range of capabilities for SQL Server, rather than simplifying them to work for both platforms. We apologize for any inconvenience.
DBMetatdata.java DebugExample.java DriverMgr.java ExecuteQuery.java
ExecuteUpdate.java GetObject.java JdbcDriver.java MyConnection.java
MyDriver.java MyResultSet.java Ping.java RSMetatdata.java
SetObject.java SimpleSelect.java SybEedInfo.java Validate.java
Version.java