Download JDBC™ 2.0 (Java Database Connectivity)

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts
no text concepts found
Transcript
Support Readiness Document
JDBC™ 2.0
(Java Database Connectivity)
Java™ 2 Platform
Sun Microsystems, Inc.
Java Software
Support Readiness Document
JDBC™ 2.0
(Java Database Connectivity)
Java™ 2 Platform
Sun Microsystems, Inc.
Java Software
901 San Antonio Road
Palo Alto, CA 94303
U.S.A.
Version: 1.J2
Release Date: January 15, 1999
 1999 by Sun Microsystems, Inc.—Printed in USA.
901 San Antonio Road, Palo Alto, California 94303
All rights reserved. No part of this work covered by copyright may be duplicated by any
means—graphic, electronic or mechanical, including photocopying, or storage in an information
retrieval system—without prior written permission of the copyright owner.
RESTRICTED RIGHTS LEGEND: Use, duplication, or disclosure by the government is subject to
restrictions as set forth in subparagraph (c)(1)(ii) of the Rights in Technical Data and Computer
Software clause at DFARS 252.227-7013 (October 1988) and FAR 52.227-19 (June 1987). The
product described in this manual may be protected by one or more U.S. patents, foreign patents,
and/or pending applications.
TRADEMARKS: Java, Java Database Connectivity, Java Naming and Directory Interface, Java 2
platform, 100% Pure Java, JavaBeans, HotJava, JDBC, JNI, and Sun Microsystems are trademarks
of Sun Microsystems, Inc. Solaris SPARC (Platform Edition) is a trademark of Sun Microsystems,
Inc. All SPARC trademarks are used under license and are trademarks or registered trademarks
of SPARC International, Inc. in the United States and other countries. Products bearing SPARC
trademarks are based upon an architecture developed by Sun Microsystems, Inc. UNIX is a
Sun Microsystems, Inc.
Java Software
901 San Antonio Road
Palo Alto, CA 94303
U.S.A.
Table of Contents
Preface iii
1.0 JDBC 2.0 Overview
1.1
1.2
1.3
1.4
1
Release History 2
Other Software 2
Features, Advantages, & Benefits
New in JDBC 2.0 3
3
1.4.1 New Features in the Core API 3
1.4.2 New Features in the Standard Extension API
2.0 Product Distribution
3
4
3.0 Requirements and Dependencies
4
3.1 Software and System Requirements and Dependencies 4
3.2 Product Compatibility 4
3.2.1 Interoperability with Existing Sun and Third-Party Software
3.2.2 Versions 5
3.2.3 Backward/Forward Compatibility With Other Versions 5
4.0 Installing JDBC
5
5.0 JDBC Uninstall
5
6.0 Using JDBC
4
6
7.0 Tuning and Troubleshooting
6
7.1 Common User Questions 6
7.1.1 Why
Does
Calling
Class.forName("jdbc.odbc.JdbcOdbcBridge") Result in a “Class Not Found” Error? 6
7.1.2 Why Does Calling Class.forName(aClassName) Result in a “Class
Not Found” Error? 6
7.1.3 What Causes the “No suitable driver” Error? 6
7.1.4 How Can I Tell if My JDBC Driver is Being Loaded and Registered With
the
DriverManager? 6
7.1.5 What’s the Best Way to Start Debugging a JDBC-related Problem? 6
SUN MICROSYSTEMS, INC.
i
Table of Contents
7.1.6 What is JDBC 2.0? 7
7.1.7 Does the JDBC-ODBC Bridge Support the New Features in JDBC
2.0? 7
7.1.8 Can the JDBC-ODBC Bridge Be Used With Applets? 7
7.1.9 Can JDBC Be Used to Access a Desktop Database Like Microsoft Access
Over the Network? 7
7.1.10 Does the JDBC-ODBC Bridge From Sun Work with Microsoft J++? 8
7.1.11 JDBC Performance Question 8
7.1.12 SQLState: IM002 Message 8
7.1.13 Are All the Required JDBC Drivers to Establish Connectivity to My Database Part of the Java 2 Platform? 8
7.1.14 Is the JDBC-ODBC Bridge Multi-Threaded? 8
7.1.15 I Can’t Retrieve More Than 255 characters From an Oracle v7.0.3 database. Is JDBC broken? 9
7.1.16 Does the Bridge Support Multiple Concurrent Open Statements per Connection When Accessing MS SQL Server? 9
7.1.17 Does the Sun JDBC-ODBC Driver Support Result Sets Which Contain
Japanese Characters (DBCS)? 9
7.1.18 Could You Recommend a Good Book for Learning JDBC? 9
7.1.19 Problems Invoking Methods of ResultSet such as afterLast(),
beforeFirst(), and first(), Whereas rs.next() is Working Fine.
What’s Wrong? 9
7.1.20 Is There a Method to Find the Number of Rows in a ResultSet? 9
7.1.21 If I Use JDBC, Do I Have to Use ODBC Underneath? 9
7.1.22 Besides the Java 2 Platform, What Else Do I Need to Connect to a
Database? 9
7.1.23 How Do I Download the JDBC-ODBC Bridge? 10
7.1.24 Which Versions of ODBC and DBMS are Tested and Considered
Stable? 10
7.1.25 Question About SQL2 INTERVAL Datatype 10
7.2 Troubleshooting Utilities
8.0 Reference Information
10
10
8.1 Technical Documentation 10
8.2 Additional References 10
8.2.1
8.2.2
8.2.3
8.2.4
8.2.5
8.2.6
8.2.7
8.2.8
8.2.9
JDBC FAQ 10
The Java 2 Platform JDBC Page 10
JDBC Tutorial 10
JDBC Overview 10
JDBC Vendors 11
JDBC Drivers 11
Java Series Book on JDBC 11
JDBC 2.0 Software Download 11
JDBC 1.0 Software Download 11
SUN MICROSYSTEMS, INC.
ii
Preface
This document provides Support Readiness information for JDBC 2.0. The goal of Support Readiness Documents (SRDs) is to help support engineers prepare to support Java
Software products. SRDs are not designed to provide comprehensive product training
(see the product documentation or Sun Education for this). Instead, they focus on issues
immediately relevant to support, such as installation, configuration, and common user
problems.
Document Format Options: PDF and PostScript
The JDBC 2.0 SRD can be viewed in PostScript or PDF format. The PDF version of the
document allows navigation via a table of contents frame, and the benefit of live cross
references and web links. Text that is underlined and in blue, such as the URL in this
paragraph, are clickable links in the PDF version of the document. (Note: page numbers
in the PDF document refer to printed pages, and will not coincide with the page numbers in the PDF reader status bar.) Although the blue color and underlining appear in the
PostScript version, there are no live links when viewing that version.
Typographic Conventions
This document uses the following type conventions:
• The names of commands, files, Java™ objects, Java classes, and directories are
shown in regular monospace font.
• Text that is a placeholder to be replaced with a real name or value appears in italic
type; for example: % unzip jsdt-1.4.zip -d destination directory.
• Text that you type, when shown alongside computer output such as a command
prompt, is shown in bold monospace font. The marker “prompt>,” in regular
monospace font, represents the actual command prompt you would see on your
screen, which may vary depending on your specific environment, shell, or platform.
For example: Solaris prompt> ls -l.
• The names of menu items, buttons, windows, and keyboard keys appear in regular
font with initial capitals, such as the Enter key.
• URLs that are clickable web links in the PDF version of the document are shown in
blue, underlined monospace font, as in http://java.sun.com. Although the blue
color and underlining appears in the PostScript version, there are no live links when
viewing that version.
SUN MICROSYSTEMS, INC.
iii
Preface
• URLs that are not clickable web links are shown in regular monospace font, such as
jsdt://stard:5555/socket/Session/chatSession.
• Cross-references to other sections of the document are shown in regular font but are
blue and underlined, as in, See Section 1.0, “JSDT Overview.” In the PDF version of
the document, these are clickable links to the indicated section. Although the blue
color and underlining appears in the PostScript version, there are no live links when
viewing that version.
• New terms and book titles appear in italic type.
SUN MICROSYSTEMS, INC.
iv
JDBC 2.0
1.0 JDBC 2.0 Overview
The Java™ Database Connectivity (JDBC™) 2.0 application programming interface
(API) is the latest update of the JDBC API. JDBC 2.0 contains many new features,
including:
•
•
•
•
•
•
•
Scrollable result sets
Performance enhancements
Support for SQL3 data types
Java Naming and Directory Interface™ (JNDI) support
Connection pooling
Distributed transactions
JavaBeans™ support in the form of RowSet
There are two parts to JDBC 2.0:
• JDBC 2.0 Core API – Included in the Java™ 2 platform release; consists of the contents of the java.sql package.
Note: The Java 2 platform was previously known as the Java Development Kit (JDK™)
1.2.
• JDBC 2.0 Standard Extension API – Consists of the contents of the javax.sql
package (note that there are two separate packages). The standard extension is not
currently bundled with any JDK/Java platform products from Sun Microsystems™,
Inc. but it may be in the future. Currently, the standard extension is available as a
separate software download from http://java.sun.com/products/jdbc.
SUN MICROSYSTEMS, INC.
1 of 11
JDBC 2.0 Overview
JDBC 2.0 is expressed primarily as a set of interfaces in the Java programming language, therefore, the java.sql (core) and javax.sql (standard extension) packages
mainly contain compiled Java interfaces, and not an actual implementation of the JDBC
API that would allow a Java program to access a database. Implementations of the
JDBC API—called JDBC drivers—are provided separately, usually by an independent
software vendor (ISV).
1.1 Release History
The JDBC 2.0 Core API was finalized in May 1998, and has been included in all the
Java 2 platform releases since that time. The JDBC 2.0 Standard Extension API was
finalized in December 1998. For a list of available JDBC drivers, see
http://java.sun.com/products/jdbc.
Prior to the release of the Java 2 platform, JDBC 1.0—sometimes referred to as JDBC
1.2—was available with the JDK 1.1. JDBC 1.0 consisted of the contents of the
java.sql package. Thus, JDBC 1.0 corresponds to the previous release of the JDBC
2.0 Core API which contains the new contents of java.sql. This package has undergone major changes with the release of JDBC 2.0. New methods have been added to
most of the existing interfaces in java.sql, and there are several new interfaces that
have been added as well.
1.2 Other Software
The following pieces of software related to JDBC are also available:
• JDBC-Open Database Connectivity (ODBC) Bridge – The JDBC-ODBC bridge is a
JDBC driver that provides JDBC access using most ODBC drivers. Sun provides the
bridge as a way to allow developers to get started with JDBC. The bridge is intended
to be used for prototyping of applications, and does not compete with commercial
JDBC products.
• The JDBC test suite and harness – In order to insure that applications are portable
across different JDBC drivers, Sun and Intersolv have jointly developed a JDBC
driver test suite. You need both the Test Harness and Test Suite to test a JDBC
Driver. The Test Suite provides a profile of a JDBC driver’s capabilities; however, it
is not comprehensive enough to be used for driver certification. There is currently no
program for certifying JDBC drivers as JDBC-compliant.
• The JDBC test tool – The JDBC Test tool (provided to Sun Microsystems, Inc. by
Intersolv) facilitates experimenting with JDBC commands. This tool allows users
and driver developers to test JDBC commands using an easy-to-use graphical user
interface (GUI). It is written in 100% Pure Java™ and can be used either as a program or as an applet.
At this time (January 1999) none of the software components listed above have been
upgraded to support the new features in the JDBC 2.0 API. We are hoping to release a
version of the JDBC-ODBC bridge that supports some of the new features in JDBC 2.0
in the Java 2.2 platform release.
SUN MICROSYSTEMS, INC.
2 of 11
JDBC 2.0 Overview
1.3 Features, Advantages, & Benefits
JDBC is a standard data access interface, developed by Sun Microsystems, Inc. and its
Java partners. This API provides Java programmers with universal access to a wide
range of relational databases. As mentioned above, JDBC 2.0 is a standard part of the
Java 2 Platform.
JDBC is the Java 2 platform equivalent of other data access APIs that have been created
by Microsoft—including ADO, OleDb, and ODBC—which are collectively termed
UDA (Universal Data Access) by Microsoft. JDBC 2.0 contains all of the important features of these APIs, and goes beyond them in significant ways. For example, JDBC 2.0
supports SQL3 data types, like arrays and structured types, as well as providing the
means to store Java objects directly in a database (SQLJ support).
1.4 New in JDBC 2.0
This section lists the new features in the JDBC 2.0 API. New features in the JDBC 2.0
Core API (java.sql) are listed separately from new features in the JDBC 2.0 Standard
Extension API (javax.sql).
1.4.1
New Features in the Core API
• Scrollable result sets – The JDBC 1.0 API provided result sets that had the ability to
scroll in a forward direction only. Scrollable result sets allow for more flexibility in
the processing of results by providing both forward and backward movement
through their contents. In addition, scrollable result sets allow for relative and absolute positioning. For example, it’s possible to move to the fourth row in a scrollable
result set directly, or to move directly to the third row following the current row, provided the row exists.
• Updatable result sets – JDBC 2.0 allows result sets to be directly updatable. Programmatic updates, deletes, and inserts of rows in a result set are supported.
• Batch updates – The batch update feature allows an application to submit multiple
update statements (insert/update/delete) in a single request to the database. This can
provide a dramatic increase in performance when a large number of update statements need to be executed.
• Advanced data types – Increased support for storing persistent Java objects and a
mapping for SQL3 data types such as binary large objects (BLOBs), and structured
types, has been added to JDBC 2.0. An application may also customize the mapping
of SQL3 structured types into Java language classes.
• Other new features – Support for character streams has been added. This means that
character data can be retrieved and sent to the database as a stream of internationalized Unicode characters. Methods to allow java.math.BigDecimal values to
be returned with full precision have also been added. Support for time zones has
been added.
1.4.2
New Features in the Standard Extension API
• Rowsets – As its name implies, a rowset encapsulates a set of rows. A rowset may or
may not maintain an open database connection. When a rowset is disconnected from
SUN MICROSYSTEMS, INC.
3 of 11
Product Distribution
its data source, updates performed on the rowset are propagated to the underlying
database using an optimistic concurrency control algorithm.
Rowsets add support to the JDBC API for the JavaBeans component model:
– A rowset object is a Java Bean.
– A rowset implementation may be serializable.
– Rowsets can be created at design time and used in conjunction with other JavaBeans components in a visual JavaBeans builder tool to construct an application.
• JNDI for naming databases – The JNDI can be used in addition to the JDBC driver
manager to obtain a connection to a database. When an application uses JNDI, it
specifies a logical name that identifies a particular database instance and JDBC
driver for accessing that database. This has the advantage of making the application
code independent of a particular JDBC driver and JDBC URL.
• Connection pooling – JDBC 2.0 contains hooks that allow connection pooling to be
implemented on top of the JDBC driver layer. This allows for a single connection
cache that spans the different JDBC drivers that may be in use. Since creating and
destroying database connections is expensive, connection pooling is important for
achieving good performance, especially for server applications.
• Distributed transaction support – Support for distributed transactions has been added
as an extension to JDBC 2.0. This feature allows a JDBC driver to support the standard 2-phase commit protocol used by the Java Transaction Service (JTS).
2.0 Product Distribution
You can download a copy of the Java 2 platform, which contains the JDBC 2.0 Core
API, free of charge from http://java.sun.com/products/jdk/1.2.
The JDBC-ODBC bridge is also bundled in the Java 2 platform release. The bridge
resides in package sun.jdbc.odbc.JdbcOdbcBridge.
The JDBC 2.0 Standard extension API, JDBC test suite and harness and the JDBC test
tool can be downloaded from http://java.sun.com/products/jdbc.
The source code to the test suite and the bridge can be licensed for a fee.
3.0 Requirements and Dependencies
3.1 Software and System Requirements and Dependencies
These requirements are the same as for the Java 2 platform.
3.2 Product Compatibility
3.2.1
Interoperability with Existing Sun and Third-Party Software
JDBC interoperability with existing Sun and third-party software is the same as for the
Java 2 platform.
SUN MICROSYSTEMS, INC.
4 of 11
Installing JDBC
3.2.2
Versions
• JDBC 1.0 – This was the first public release of the JDBC, and was compatible, but
not included, in the JDK 1.0.2.
• JDBC 1.2 – This release contains some minor changes relative to JDBC 1.0. JDBC
1.2 is available for download for the JDK 1.0.2 and is included in the JDK 1.1.
• JDBC 2.0 – This release is the second major public release of the JDBC API. The
JDBC 2.0 Core API is included in the Java 2 platform. The JDBC 2.0 Standard
Extension API is available for download separately and is compatible with the Java 2
platform.
3.2.3
Backward/Forward Compatibility With Other Versions
Existing JDBC 1.0 drivers and the Java applications that use them continue to work—
unchanged—in a Java virtual machine that supports the JDBC 2.0 API. Applications
that don’t use any of the new features of JDBC 2.0 do not require any changes to continue running. It should be straightforward for existing applications to migrate to the
new JDBC API.
4.0 Installing JDBC
To install the JDBC Core API and the JDBC-ODBC bridge, install the Java 2 platform.
See the Java 2 platform documentation for installation details at the following URLs:
• Solaris: – http://java.sun.com/products/jdk/1.2/
install-solaris.html.
• Win32 – http://java.sun.com/products/jdk/1.2/
install-windows.html.
Before using the JDBC-ODBC bridge, you must also install and configure the ODBC
driver manager, an ODBC driver, and an ODBC data source. The requirements for
installing ODBC vary between vendors and platforms.
The JDBC Standard Extension API, JDBC test suite and harness, and the JDBC test tool
are 100% Pure Java, and are installed by installing their respective JAR and ZIP files in
the usual way for a particular platform.
5.0 JDBC Uninstall
The overview SRD for the Java 2 platform provides information on uninstalling the Java
2 platform on either the Solaris or Win32 platforms:
See Section 5, “Uninstalling the Java 2 Platform” of the Java 2 Platform SRD at:
http://access1.sun.com/SRDs/access1_srds.html.
SUN MICROSYSTEMS, INC.
5 of 11
Using JDBC
6.0 Using JDBC
Currently, the JDBC 2.0 specifications are the best source for information about JDBC.
For more information, see http://java.sun.com/products/jdbc.
A new Java series book is planned for JDBC 2.0, and should be available around June
1999.
7.0 Tuning and Troubleshooting
7.1 Common User Questions
7.1.1
Why Does Calling Class.forName("jdbc.odbc.JdbcOdbcBridge") Result in a
“Class Not Found” Error?
The class name specified is incorrect. The correct class name for the bridge is
sun.jdbc.odbc.JdbcOdbcBridge.
7.1.2
Why Does Calling Class.forName(aClassName) Result in a “Class Not Found”
Error?
In general, the JDBC driver class must be accessible to the virtual machine (VM) by
being in the class path. If it is not, this error will occur.
7.1.3
What Causes the “No suitable driver” Error?
This error usually occurs during a call to DriverManager.getConnection(). The
cause can be failing to load the appropriate JDBC driver before calling
getConnection(), or specifying an invalid JDBC URL—one that isn’t recognized by
the JDBC driver. Developers should check their JDBC driver’s product documentation
or contact their JDBC driver vendor if they suspect that the URL they are specifying is
not being recognized by their JDBC driver.
When using the JDBC-ODBC bridge, the cause can also be that some of the native
libraries needed by the bridge aren’t being found (a configuration problem) and this is
preventing the bridge responding positively to the connection request.
7.1.4
How Can I Tell if My JDBC Driver is Being Loaded and Registered With the
DriverManager?
Enable JDBC logging/tracing by calling the JDBC 1.0 method,
DriverManager.setLogStream(), or the JDBC 2.0 method,
DriverManager.setLogWriter(). The log that is produced will tell you what is
going on under the covers. Looking at a JDBC trace is a good first step in debugging
almost any JDBC related problem.
7.1.5
What’s the Best Way to Start Debugging a JDBC-related Problem?
See the answer to Section 7.1.4, “How Can I Tell if My JDBC Driver is Being Loaded
and Registered With the DriverManager?”
SUN MICROSYSTEMS, INC.
6 of 11
Tuning and Troubleshooting
7.1.6
What is JDBC 2.0?
JDBC 2.0 is the latest update of the JDBC API. JDBC 2.0 contains features such as
scrollable result sets. There are two parts to JDBC 2.0: the JDBC 2.0 Core API and the
JDBC 2.0 Standard Extension API. The JDBC 2.0 Core API is included in the Java 2
platform release.
7.1.7
Does the JDBC-ODBC Bridge Support the New Features in JDBC 2.0?
The JDBC-ODBC bridge that is included in the Java 2 platform initial release doesn’t
support the new features in JDBC 2.0. Sun Microsystems, Inc. and Intersolv are working to produce a new version of the bridge that does support the new features in JDBC
2.0, such as scrollable result sets. Hopefully, this version of the bridge will be available
in the Java 2.2 platform release.
7.1.8
Can the JDBC-ODBC Bridge Be Used With Applets?
Use of the JDBC-ODBC bridge from an untrusted applet running in a browser, such as
Netscape Navigator, isn’t allowed. The JDBC-ODBC bridge doesn’t allow untrusted
code to call it for security reasons. This is good because it means that an untrusted
applet that is downloaded by the browser cannot circumvent Java security by calling
ODBC. Remember that ODBC is native code, so once ODBC is called, Java can’t guarantee that a security violation won’t occur. On the other hand, 100% Pure Java JDBC
drivers work well with applets. They are fully downloadable and do not require any client-side configuration.
For completeness, we would like to note that it is possible to use the JDBC-ODBC
bridge with applets that will be run in appletviewer since appletviewer assumes that
applets are trusted. It is also possible to use the JDBC-ODBC bridge with applets that
are run in the HotJava™ browser (available from Sun Microsystems, Inc.), since HotJava provides an option to turn off applet security. In general, it is dangerous to turn
applet security off, but it may be appropriate in certain controlled situations, such as for
applets that will only be used in a secure intranet environment. Exercise caution if you
chose this option, and use an all-Java JDBC driver whenever possible to avoid security
problems.
7.1.9
Can JDBC Be Used to Access a Desktop Database Like Microsoft Access Over the
Network?
Most desktop databases (Access, Foxpro) currently require a JDBC solution that uses
ODBC underneath. This is because the vendors (e.g., MicroSoft) of these database
products haven’t implemented JDBC drivers for them. The best approach is to use a
commercial JDBC driver that supports ODBC and the database you want to use. See the
JDBC drivers web page for a list of available JDBC drivers.
The JDBC-ODBC bridge from Sun does not provide network access to desktop databases by itself. The JDBC-ODBC bridge loads ODBC as a local DLL, and typical
ODBC drivers for desktop databases like Access aren’t networked. The JDBC-ODBC
bridge can be used together with an RMI-JDBC bridge, however, to access a desktop
database like Access over a network. This RMI-JDBC-ODBC solution is free. The
RMI-JDBC bridge is available from http://dyade.inrialpes.fr/
mediation/download/.
SUN MICROSYSTEMS, INC.
7 of 11
Tuning and Troubleshooting
7.1.10
Does the JDBC-ODBC Bridge From Sun Work with Microsoft J++?
No, J++ does not support the JDBC-ODBC bridge since it doesn’t implement the
Java™ Native Interface (JNI). Any all-Java JDBC driver should work with J++, however. In addition, Microsoft ships its own JDBC-ODBC bridge which developers may
load by calling
Class.forName("com.ms.jdbc.odbc.JdbcOdbcDriver"). The Microsoft
bridge works with J++.
7.1.11
JDBC Performance Question
This question involves whether there is a way to retrieve a whole row of data at once,
instead of calling an individual ResultSet.getXXX() method for each column.
All of these method calls are slowing things down. The ResultSet.getXXX() methods are the only way to retrieve data from a ResultSet object, hence it is necessary to
do a method call for each column of a row. Its unlikely that this is the cause of a performance problem, however, since its difficult to see how a column could be fetched without at least the cost of a function call in any scenario. This issue is being studied, and we
welcome input on it from developers.
7.1.12
SQLState: IM002 Message
Question: I’m receiving the following error when using the JDBC-ODBC bridge.
What’s the problem?
“SQLState: IM002 Message: [Microsoft][ODBC Driver Manager]
Data source name not found and no default driver specified
Vendor: 0”
This type of error occurs during an attempt to connect to a database with the bridge.
First, note that the error is coming from the ODBC driver manager. This indicates that
the bridge—which is a normal ODBC client—has successfully called ODBC, so the
problem isn’t due to native libraries not being present. In this case, it appears that the
error is due to the fact that an ODBC DSN (data source name) needs to be configured on
the client machine. Developers often forget to do this, thinking that the bridge will magically find the DSN they configured on their remote server machine.
7.1.13
Are All the Required JDBC Drivers to Establish Connectivity to My Database Part
of the Java 2 Platform?
There aren’t any JDBC drivers bundled with the JDK 1.1.x or the Java 2 platform FCS
releases other than the JDBC-ODBC bridge. So, developers need to get a driver and
install it before they can connect to a database. Sun is considering bundling JDBC drivers in the future.
7.1.14
Is the JDBC-ODBC Bridge Multi-Threaded?
No, the JDBC-ODBC does not support concurrent access from different threads. The
JDBC-ODBC bridge uses synchronized methods to serialize all of the calls that it makes
to ODBC. Multi-threaded Java programs may use the bridge, but they won’t get the
advantages of multi-threading. In addition, deadlocks can occur between locks held in
the database and the semaphore used by the bridge. Sun may remove the synchronized
methods in the future. They were added originally to make things simple for people
writing Java programs that use a single-threaded ODBC driver.
SUN MICROSYSTEMS, INC.
8 of 11
Tuning and Troubleshooting
7.1.15
I Can’t Retrieve More Than 255 characters From an Oracle v7.0.3 database. Is
JDBC broken?
Once a Connection has been made, runtime errors like this are almost always due to a
bug in the JDBC driver (in this case the Oracle driver). This is because JDBC doesn’t
interpose any code between a Java application and the driver—the application calls the
driver classes that implement the JDBC interfaces directly. Developers will need to get a
fix from their JDBC driver vendor.
7.1.16
Does the Bridge Support Multiple Concurrent Open Statements per Connection
When Accessing MS SQL Server?
No. Only a single Statement per Connection may be open at a time when using the
bridge.
7.1.17
Does the Sun JDBC-ODBC Driver Support Result Sets Which Contain Japanese
Characters (DBCS)?
Yes, but we haven’t tested this. The bridge in the Java 2 platform also supports a new
charSet connection property for specifying the character encoding used by the underlying DBMS. For more information, see http://java.sun.com/
products/jdk/1.2/docs/guide/jdbc/bridge.html.
7.1.18
Could You Recommend a Good Book for Learning JDBC?
The Java Series book, JDBC Database Access with Java is a good book for learning
about JDBC 1.0. It is published by Addison Wesley. A new book that covers JDBC 2.0
is in the works, and will hopefully be available beginning in June 1999.
7.1.19
Problems Invoking Methods of ResultSet such as afterLast(), beforeFirst(),
and first(), Whereas rs.next() is Working Fine. What’s Wrong?
You are likely using a JDBC 1.0 driver that doesn’t support scrollable cursors. You need
to upgrade to a JDBC 2.0 driver.
7.1.20
Is There a Method to Find the Number of Rows in a ResultSet?
When using a scrollable result set one can call either:
rs.last();
rs.getRow();
to find out how many rows are in a ResultSet. If the ResultSet isn’t scrollable one
must either count the rows by iterating through the ResultSet or submit a query with
a COUNT column in the select clause.
7.1.21
If I Use JDBC, Do I Have to Use ODBC Underneath?
No, this is just one of many possible solutions. You should use a pure Java JDBC driver,
type 3 or type 4, in order to get all of the benefits of Java and JDBC.
7.1.22
Besides the Java 2 Platform, What Else Do I Need to Connect to a Database?
You still need to get and install a JDBC driver that supports the database that you are
using. There are many drivers available from a variety of sources. You can also try using
the JDBC-ODBC bridge, if you have ODBC connectivity setup already. The bridge
comes with the Java 2 platform, and doesn’t require any extra setup itself. The bridge is
a normal ODBC client.
SUN MICROSYSTEMS, INC.
9 of 11
Reference Information
7.1.23
How Do I Download the JDBC-ODBC Bridge?
The bridge is bundled with the Java 2 platform, so there is no need to download it separately.
7.1.24
Which Versions of ODBC and DBMS are Tested and Considered Stable?
Sun Microsystems, Inc. hasn’t performed testing on the ODBC drivers and databases.
The bridge is a simple tool that is provided to let people begin using JDBC. It is not a
commercial quality data access solution. Use with care.
7.1.25
Question About SQL2 INTERVAL Datatype
Question: In your documentation you explain how JDBC 2.0 is able to handle the new
SQL3 data types. But what about INTERVAL? INTERVAL is a SQL2 built-in data type
and has no correspondence in JDBC/Java.
Interval isn’t widely supported by DBMS products even though it is part of SQL92.
JDBC does not support this type because applications that use it would not be portable.
7.2 Troubleshooting Utilities
The best way to begin debugging many JDBC-related problems is to enable JDBC logging/tracing by calling the JDBC 1.0 method, DriverManager.setLogStream(), or
the JDBC 2.0 method, DriverManager.setLogWriter(). The log that is produced
will tell you what is going on under the covers. Looking at a JDBC trace is a good first
step in debugging almost any JDBC related problem.
8.0 Reference Information
8.1 Technical Documentation
The main site for JDBC is http://java.sun.com/products/jdbc.
8.2 Additional References
The following are other URLs for specific information:
8.2.1
JDBC FAQ
http://java.sun.com/products/jdbc/jdbc-frequent.html
8.2.2
The Java 2 Platform JDBC Page
http://java.sun.com/products/jdk/1.2/docs/guide/
jdbc/index.html
8.2.3
JDBC Tutorial
http://java.sun.com/products/jdk/1.2/docs/guide/jdbc/
getstart/introTOC.doc.html
8.2.4
JDBC Overview
|http://java.sun.com/products/jdbc/overview.html
SUN MICROSYSTEMS, INC.
10 of 11
Reference Information
8.2.5
JDBC Vendors
http://java.sun.com/products/jdbc/jdbc.vendors.html
8.2.6
JDBC Drivers
http://developer.java.sun.com/jdbc.drivers.html
8.2.7
Java Series Book on JDBC
http://java.sun.com/products/jdbc/book.html
8.2.8
JDBC 2.0 Software Download
http://java.sun.com/products/jdbc/jdbcse2.html
8.2.9
JDBC 1.0 Software Download
http://java.sun.com/products/jdbc/jdbcsw2.html
SUN MICROSYSTEMS, INC.
11 of 11