Using jdbcKona/MSSQLServer4
- I. Introduction
- What's in this document
- II. Using jdbcKona/MSSQLServer4
- Connecting to SQL Server with jdbcKona/MSSQLServer4
- Setting properties for Microsoft SQL Server 7
- Setting properties for WebLogic JDBC use
- Codeset support
- Using jdbcKona/MSSQLServer4 in applets
- Using jdbcKona/MSSQLServer4 in Java development environments
- III. JDBC extensions and limitations
- Support for JDBC extended SQL
- cursorName() method not supported
- java.sql.TimeStamp class limitations
- Querying meta data
- Statement.executeWriteText() methods not supported
- Sharing a Connection object in multi-threaded applications
- Changing autoCommit mode
- Execute keyword with stored procedures
- IV. Change history
- Other related documents
- Installing WebLogic (non-Windows)
- Installing WebLogic (Windows)
- Installing
jdbcKona/MSSQLServer4
- Using WebLogic JDBC
- Developers Guides
- API Reference Manual
- Package
java.sql (JDBC API reference)
- Package
java.math (JDBC API reference)
- Performance tuning your JDBC application
- Troubleshooting JDBC hangs and SEGVs
- Choosing a Java Database Connectivity driver
- Code examples
- Glossary
I. Introduction
What's in this document
This document provides information on how to set up and use
WebLogic's jdbcKona/MSSQLServer4 JDBC driver. WebLogic acquired this product,
formerly known as FastForward, from Connect Software in April 1998.
jdbcKona/MSSQLServer4 is a Type 4, pure-Java, two-tier
driver. It requires no client-side libraries since it connects to the
database via a proprietary vendor protocol at the wire-format level.
Unlike Type 2 JDBC drivers, Type 4 drivers make no "native" calls, so
they can be used in Java applets
.
A Type 4 JDBC driver is similar to a Type 2 driver in many other ways.
Type 2 and Type 4 drivers are two-tier drivers -- each client requires
an in-memory copy of the driver to support its connection to the database.
For more information on the four types of JDBC drivers, read the
whitepaper Choosing a JDBC Driver.
Within the WebLogic environment, you can use a Type 2 or a Type 4
two-tier driver to connect the WebLogic Server
to a database, and then use WebLogic JDBC, WebLogic's pure-Java Type 3
multitier
JDBC driver, for client connections to the WebLogic Server. For more
information on how WebLogic JDBC works with any two-tier driver, and
how connections are structured in WebLogic, read the Tech Tip, What do I do with all
these connections, anyway?
If you are using jdbcKona/MSSQLServer4 with WebLogic JDBC, you should also
refer to the Developers Guide Using WebLogic JDBC for more information.
This JDBC driver is only supported with versions
of the JDK
later than 1.1. There is no JDK 1.0.2 support.
This JDBC driver works with Microsoft SQL Server versions 6.5 and 7.0.
It is shipped in two versions -- one that supports both versions 6.5 and 7.0,
but does not support any version 7.0 specific features -- and one that only
supports version 7.0 and the new SQL Server 7.0 nchar, nvarchar, and
ntext datatypes. Both are available from the same download page.
The API reference for JDBC, of which this driver is a fully
compliant implementation, is available online in several formats at
JavaSoft.
II. Using jdbcKona/MSSQLServer4
Connecting to SQL Server with jdbcKona/MSSQLServer4
To connect to a SQL Server database in a Java program, you:
- Load the jdbcKona/MSSQLServer4 JDBC driver
- Request a JDBC connection
An efficient way to load the JDBC driver is to call Class.forName().newInstance() with
the name of the driver class, as in this example:
Class.forName("weblogic.jdbc.mssqlserver4.Driver").newInstance();
After loading the JDBC driver, request a JDBC connection by calling
the DriverManager.getConnection() method. You call this
method with a connection URL, which again specifies the JDBC
driver, and other connection information.
There are several ways to specify connection information in the DriverManager.getConnection() method.
This document describes three methods.
For a full code example, check the beginning sections in the
Implementation guide in the overview,
Using the jdbcKona family of JDBC drivers.
Method 1
The simplest method is to use a connection URL that includes
the database name, host name and port number of the database server, and two
additional arguments to specify the database user name and password:
Class.forName("weblogic.jdbc.mssqlserver4.Driver").newInstance();
Connection conn =
DriverManager.getConnection(
"jdbc:weblogic:mssqlserver4:database@host:port",
"sa", // database user name
""); // password for database user
where host is the name or IP number
of the computer running SQL Server and port
is the port number the SQL Server is listening on.
Method 2
You can set connection information in a Properties object and pass this
to the DriverManager.getConnection()
method. The following example specifies the server, user, and password in a Properties
object:
Properties props = new Properties();
props.put("server", "pubs@myhost:1433");
props.put("user", "sa");
props.put("password", "");
// props.put("appname", "MyApplication");
// props.put("hostname", "MyHostName");
// The last two properties, "appname" and "hostname" are optional and
// are passed to MS SQL server, where they can be read in the
// sysprocesses table under the column names "program_name" and "hostname".
// The hostname value will be prepended with "WebLogic"
Class.forName("weblogic.jdbc.mssqlserver4.Driver").newInstance();
Connection conn =
DriverManager.getConnection("jdbc:weblogic:mssqlserver4", props);
Method 3
You can add connection options to the end of the connection URL instead of
creating a Properties object. Separate the URL from the connection options with
a question mark and separate options with ampersands, as in this example:
Class.forName("weblogic.jdbc.mssqlserver4.Driver).newInstance();
DriverManager.getConnection(
"jdbc:weblogic:mssqlserver4:database@myhost:myport?user=sa&password=");
You can use Driver.getPropertyInfo()
to find out more about URL options at run-time.
Setting properties for Microsoft SQL Server 7
Microsoft SQL Server 7 has a slightly different login packet than
earlier versions. Beginning with jdbcKona/MSSQLServer4 release 3.1.6,
jdbcKona/MSSQLServer4 recognizes SQL Server 7 automatically. If you
are using an earlier release, we
recommend that you upgrade to the new release. Otherwise, you must
set the sql7 property to "true" to
connect to SQL Server 7. You can set the property either in the
connection URL or in a Properties object. For example, the connection
URL for a SQL Server 7 connection would be similar to the following:
"jdbc:weblogic:mssqlserver4:pubs@myhost:myport?sql7=true"
Setting properties for WebLogic JDBC use
If you are using WebLogic JDBC in a multitier environment with a two-tier jdbcKona driver, you set connection properties in a slightly different way. See Using WebLogic JDBC for more details.
Codeset support
As a Java application, jdbcKona/MSSQLServer4 handles character strings
as Unicode
strings. To exchange character strings with a database that may
operate with a different codeset, the driver attempts to detect the
codeset of the database and convert Unicode strings using a character
set supported by the JDK. If there is no direct mapping between the
codeset of your database and the character sets provided with the JDK,
you can set the weblogic.codeset
connection property to the most appropriate Java character set. You
can find the List
of supported encodings at the JavaSoft website.
For example, to use the cp932 codeset, create a Properties object and
set the weblogic.codeset property before
calling DriverManager.getConnection(),
as in this example:
java.util.Properties props = new java.util.Properties();
props.put("weblogic.codeset", "cp932");
props.put("user", "sa");
props.put("password", "");
String connectUrl = "jdbc:weblogic:mssqlserver4:myhost:1433";
Class.forName("weblogic.jdbc.mssqlserver4.Driver").newInstance();
Connection conn =
DriverManager.getConnection(connectUrl, props);
Using jdbcKona/MSSQLServer4 in applets
Since jdbcKona/MSSQLServer4 is 100% Java, you can use it in Java
applets. The examples/jdbc/mssqlserver4
directory includes Java applets to help you set up jdbcKona/MSSQLServer4
for use in applets. See the examples documentation
for information about setting up and running the examples.
If you are planning to use jdbcKona/MSSQLServer4 in an applet in a
two-tier configuration, you will need to install the driver on your
webserver host. In addition, the webserver and the SQL Server must
be located on the same machine. Because an applet must communicate
only with the host from which its classes were loaded, the SQL Server
and the webserver must be on the same IP
host.
One way to overcome applet security restrictions is to use jdbcKona/MSSQLServer4
in a three-tier configuration with a server such as the WebLogic Server. In this configuration,
applets connect to WebLogic and WebLogic connects to SQL Server via jdbcKona/MSSQLServer.
For more information on using WebLogic with applets, read Using WebLogic for applet programming.
The SocketApplet applet tests whether the driver can
connect to the SQL Server socket.
Once you have run SocketApplet successfully, you can
use the ConnectionApplet applet
to verify that you can log into the SQL Server.
To run SocketApplet:
- Make sure that c:\weblogic\mssqlserver4\classes is in your CLASSPATH.
- At a command prompt, change to
the weblogic\mssqlserver4\examples\jdbc\mssqlserver4 directory.
-
Edit the SocketApplet.java
file. Make the following changes (you can search for the string
"FIXME" to find the locations):
- Replace "myhost" with the name of the computer running SQL Server.
- Replace "1433" with the TCP/IP port number the SQL Server is listening
on. The default port number is 1433, but you should check for the actual
port your SQL Server is listening on.
- Save your changes and compile the applet:
javac SocketApplet.java
If you see compiler errors, make sure that the jdbcKona/MSSQLServer4
distribution is installed on the webserver's computer and that c:\weblogic\mssqlserver4\classes is in the
CLASSPATH
when you start the webserver.
-
Copy SocketApplet.html and
SocketApplet.java
into a directory served by your webserver.
- Load SocketApplet.html in your browser.
SocketApplet displays an error
message if it was unable to connect to the SQL Server socket or a
success message if it connected successfully.
Applet troubleshooting hints:
- The webserver host name in the
URL that you type in the browser must match the host name in the JDBC
connection URL. For example, if you are running the browser, SQL
Server and webserver all on the same computer, you could refer to the
computer by its name, IP number, or "localhost". Although these names
all resolve to the same computer, some browsers require the names used
to match.
- Be sure to load SocketApplet.html via a webserver. Loading the page with
a file:/// URL will not work.
- If you are unable to connect
with SocketApplet, make sure that
you test the SQL Server connectivity with dbping.
-
If you have more questions about applet security issues, read
Troubleshooting
Applet Security problems.
To run ConnectionApplet:
- Edit ConnectionApplet.java:
- Replace
"myhost" in the connection URL with the name of the computer running SQL Server
- Add your own database user name and password
Save your changes.
- Compile ConnectionApplet.java:
javac ConnectionApplet.java
-
Make sure that c:\weblogic\mssqlserver4\classes is in the CLASSPATH before you start the
webserver.
- Copy ConnectionApplet.html
and ConnectionApplet.class
into a directory served by your webserver.
- Load ConnectionApplet.html with
Appletviewer:
Appletviewer ConnectionApplet.html
The applet displays a message telling you that either the connection succeeded or that
there was an exception. The exception message will help you diagnose problems.
The jdbcKona/MSSQLServer4 distribution includes several additional examples. Refer to
code examples
for information about these examples.
Using jdbcKona/MSSQLServer4 in Java development environments
jdbcKona/MSSQLServer4 has been used successfully in the following development
environments: Java SDK 1.1.x for Sun and Windows NT, Symantec Cafe,
Symantec Visual Cafe for Windows and Macintosh, Microsoft J++, Borland
JBuilder, and Metrowerks Codewarrior.
III. JDBC extensions and limitations
Support for JDBC Extended SQL
JavaSoft's JDBC specification includes a feature called SQL
Extensions, or SQL Escape Syntax. jdbcKona/MSSQLServer4 supports
Extended SQL. For information about this feature, see Using the jdbcKona Family of JDBC
drivers.
cursorName() method not supported
The cursorName() method is not
supported, since its definition does not apply to Microsoft SQL
Server.
java.sql.TimeStamp limitations
The java.sql.TimeStamp class in the JavaSoft JDK is limited
to dates after 1970. Earlier dates raise an exception. However, if you retrieve
dates using getString(), jdbcKona/MSSQLServer4
uses its own date class to overcome the limitation.
Querying metadata
You can only query metadata for the current database. The metadata
methods call the corresponding SQL Server stored procedures, which
only operate on the current database. For example, if the current
database is master, only the metadata relative to master
is available on the connection.
Changing autoCommit mode
Call Connection.setAutoCommit() with a true or false
argument to enable or disable chained transaction mode. When
autoCommit is true, the jdbcKona/MSSQLServer4 driver begins a
transaction whenever the previous transaction is committed or rolled
back. You must explicitly end your transactions with a commit or
rollback. If there is an uncommitted transaction when you call setAutoCommit(), the driver rolls
back the transaction before changing the mode, so be sure to commit
any changes before you call this method.
Statement.executeWriteText() methods not supported
The WebLogic Type 2 jdbcKona drivers support an extension that
allows you to write text and image data into a row as part of an SQL
INSERT or UPDATE statement without using a text pointer. This
extension,
Statement.exexecuteWriteText()
requires the DB-Libary native libraries, and thus is not supported by
the jdbcKona/MSSQLServer4 JDBC driver.
To read and write text and image data with streams, you can use the
prepareStatement.setAsciiStream(), prepareStatement.setBinaryStream(),
ResultSet.getAsciiStream(), and
ResultSet.getBinaryStream() JDBC methods.
Sharing a Connection object in multi-threaded applications
jdbcKona/MSSQLServer4 allows you to write multithreaded
applications where multiple threads can share a single Connection
option. Each thread can have an active Statement object. However, if
you call Statement.cancel() on one
thread, SQL Server may cancel a Statement on a different thread. The
actual Statement that is cancelled depends on timing issues in the SQL
Server. To avoid this unexpected behavior, we recommend that you get
a separate Connection for each thread.
Execute keyword with stored procedures
A Transact-SQL feature allows you to omit the EXECUTE keyword on a stored procedure when the stored
procedure is the first command in the batch. However, when a stored
procedure has parameters, jdbcKona/MSSQLServer4 adds variable
declarations (specific to the JDBC implementation) before the procedure
call. Because of this, it is good practice to use the EXECUTE keyword for stored
procedures. Note that the JDBC extended
SQL stored procedure syntax, which does not include the EXECUTE keyword, is not affected
by this issue.
IV. Change history
- Release 3.1.11 -- April 1, 1999
- When getXXX(ColName) is called on a column that
does not exist, the driver now throws an exception instead of
returning null, 0, or false.
- Using getString() on binary data no longer causes the driver to fail.
- PreparedStatement.executeUpdate() now returns a correct
count of updated rows.
- Fixed an error that occurred
when using the Transact-SQL call UPDATETEXT to
update a TEXT or IMAGE column. SQL Server
was returning unexpected output parameters, resulting in this error
message from the driver:
TdsCallableStatement.setProcedureOutResult
- error - all parameters have already been filled
- Improved performance by optimizing processing
of DATETIME values retrieved from the database.
- getLong() now retains the correct precision when the value exceeds 53 bits.
- Release 3.1.10 --
February 23, 1999
- The driver now processes queries significantly
faster than previous releases.
- Fixed a bug where tinyint values greater than
128 were returned as negative values.
- When a query returns a column with no
name, the driver now returns an empty String ("") instead of
NULL. For example, the query
select count(*) from
table returns a single value with no column name. For
generalized tools that process SQL Server query results, an empty
String is friendlier than a null value.
- The driver implements Statement.setMaxRows() with the SQL Server set rowcount statement. However,
the set rowcount statement
affects all commands subsequently executed on the connection, where
Statement.setMaxRows() expects
the row count to be an attribute of the Statement. The driver now
accounts for this difference by executing set rowcount before executing any Statement with a
different setMaxRows() value
than the Connection's set
rowcount value.
- Release 3.1.9 -- December 1, 1998
- When changing autoCommit mode with Connection.setAutoCommit(), the
jdbcKona/MSSQLServer4 driver in previous releases committed any
uncommitted statements executed previously on the
connection. Beginning with this release, any uncommitted changes
are rolled back before changing the autoCommit mode.
-
SQL Server may return update counts from internal assignments in
triggers. The jdbcKona/MSSQLServer4 driver now handles these
results correctly.
- Release 3.1.8 -- November 18, 1998
-
When autoCommit(false) is set, jdbcKona/MSSQLServer4 begins a transaction
whenever the current transaction is committed or rolled back. The
driver was improved to recognize some instances where Microsoft SQL Server
silently rolls back a transaction so that a new transaction can be started.
- Release 3.1.6 -- October 28, 1998
- Enabled jdbcKona/MSSQLServer4 to detect SQL Server 7
automatically. The "sql7=true" connection property is no longer necessary.
You do not have to remove the connection property if it already
exists.
- The release number is no longer included in the directory pathname
where the jdbcKona/MSSQLServer driver is installed. The driver
installs into the weblogic/mssqlserver4 directory. Be sure to change the
directory name in your CLASSPATH. You can find the version number by
looking in the weblogic/mssqlserver4/version.txt file.
- Release 3.1.5 -- August 28, 1998
-
Release 3.1.5 is distributed as a .zip file that unpacks in the weblogic directory. The .jar archive
is no longer used for this product.
-
When a statement timed out on the client, the statement wasn't automatically cancelled
on the SQL Server. It was possible for SQL Server to finish executing the operation
when the client believed it was cancelled. Now Statement.Cancel() is called if a query timeout
occurs so that blocked statements are killed.
-
Previously, Statement.setQueryTimeout() affected
all statements on the connection. Now it only affects the statement on which the method was
called.
-
A bug where ResultSet.getLong() returned a 4-byte
value even when an 8-byte value was required has been fixed.
- Release 3.1.4 -- August 14, 1998
-
Fixed a bug where the driver was not recognizing an error in a callable
statement and reading large error number incorrectly.
- Fixed a bug where DatabaseMetaData.getIndexInfoQueryStr(), generated bad
SQL, causing an SQLException.
-
When the specified codeset was not available with JDK, the driver issued
a warning only, then truncated data to 8 bits. The driver now issues a
SQLException.
-
Renamed the driver to jdbc.weblogic.mssqlserver4.Driver and repackaged the
driver as a Java archive (.jar).
-
Added examples from other WebLogic JDBC drivers.
-
Modified Connection URL parsing to handle URLs as
specified in Using
URLs to set properties for a JDBC Connection.
Programs using connection URL syntax supported by previous versions of
the driver will continue to work.
-
- Release 3.1
Note that with this release, JDK 1.0.2 is no longer supported.
- Improved support for Unicode and multibyte character set
environments. jdbcKona/MSSQLServer4 automatically supports
the character set
in use in the database. Strings received and transmitted by clients
are automatically translated using the proper encoding.
- Added support for extended SQL and nested extended SQL escape sequences.
- Tested with JavaSoft JDK 1.1.6 and the latest implementations of
JDK 1.1.x on most platforms.
- Added other performance enhancements and minor bug fixes.
