Moderator (MDR): MDR-andreaw
Guest Speaker (SPK): SPK-markhapner
MDR-andreaw: Hello and welcome to Java Live. My name is Andrea Warren and I will be moderating today's chat, focused on Java Database Connectivity (JDBCTM). Our guests are Mark Hapner, Senior Staff Engineer, and Seth White, Staff Engineerboth of whom are working on the JDBC team. Please begin to send in your questions, and we will get through as many as possible.
mamatha: Is it possible to use JDBC-ODBC bridge from an applet? I am trying to load it from a Netscape 3.0 browser.
SPK-markhapner: Applets work best with Pure Java JDBC drivers. The bridge does not support applets. See the JDBC FAQ for a detailed discussion of this.
(http://splash.javasoft.com/jdbc/jdbc-frequent.html)
jimheintz: How can JDBC be used to instantiate objects such as images, audio clips, and the like? I realize there is a command called getBytes() that returns a binary array; however, in order to call getContent() a URL is needed. Do I have to read the array from JDBC, write it to local storage, and then call getContent() on the temporary file?
SPK-markhapner: I'm not familiar with the image-processing APIs, so I can't answer that part of your question. Storing images as byte arrays in the database (DB) is the normal way to handle images.
Brianf: I am trying to use JDBC to connect to an ODBC source, and have downloaded the JDBC-ODBC bridge provided by Sun. I am curious though, in the documentation, the protocol in the applet doesn't specify the IP address of the server anywhere. Does this mean that I have to download a server application like Symmantec's dbANYWHERE?
SPK-seth1: I may be repeating Mark's last answer a bit. The JDBC-ODBC bridge doesn't work well with applets, since most browsers don't allow applets to call native code for security reasons, and the bridge calls native code to talk to ODBC.
The URLs that the bridge accepts, contain an ODBC DSN that identifies the database to connect to. It's up to the underlying ODBC layer to provide connectivity to a remote database server. Usually ODBC just loads the particular database's client library to talk to the server.
jimheintz: I have been researching the storage of JavaBeansTM in a database, and it appears that a lot of "glue" would have to be written to instantiate a Bean from a JDBC binary stream. Is JavaSoft considering adding a getContent() method, or a ClassLoader to facilitate wider usage of JDBC as an object/datastorage mechinism?
SPK-markhapner: We don't have any plans to provide storage of Java objects in a DB. However, one way to do this would be via Java serialization. We are working on a project to map the state of a Java object to attributes in a table. This is restricted to values that match SQL data types.
JoeSam: Do you have any idea when/if we might see support for scrollable cursors, given that the specific DB engine supports a scrollable cursor?
SPK-seth1: We would like to add a standard scrollable cursor API to the next version of JDBC. We are working on it currently.
Malachi: Isn't JDBC Windows-specific, if it's based on ODBC? If not, how
can I be sure that my Java client will be able to issue SQL commands on, say, IBM's OS/2 Java implementation?
SPK-markhapner: There are now over 20 Pure Java JDBC drivers that have been
provided by database and middleware vendors. These work on all Java Platforms. For instance, the same jConnect from Sybase works on all JDKTM 1.1 Platforms. There is nothing Windows-specific about JDBC.
jimheintz: Is it possible to create a URL that refers to a JDBC ResultSet?
SPK-seth1: Let me see if I understand the question. Do you want to create a URL that references a particular result set object that you created at
runtime? How would you make use of the URL?
jimheintz: The reason for needing a URL is that all of the current APIs that load images (from .gif, and .jpg format), and the API that loads AudioClips
require a URL to load the data. The fundamental command that these
methods use is java.net.URL.getContent(). In order to load anything that is stored in a compressed or dataspecific format, a ContentHandler
is needed, and to get a ContentHandler a URL is needed. The only way around this, that I can see, is to read the data from the DB, save it to the file system, create a URL on that file, then invoke the ContentHandler.
This is VERY wasteful, not to mention slow. I would like to see a better, more consistent method to handle this type of situation.
SPK-seth1: We would like to look into this question. It should be possible to read an
image from a database using JDBC and display it without writing the image data to an intermediate file. If it can't be done currently, then maybe a method could be added (to the image class, for example)
to make this possible.
mamatha: I would want to test our driver with some existing Java applications
using JDBC. Can you direct me to a place where I can find such applications or products?
SPK-seth1: There is a test suite for JDBC available on the JDBC web site. It's an all-Java application. Right now the test suite isn't comprehensive
enough to certify a driver as "JDBC Compatible," but it is a nice way to see if a driver provides a wide range of functionality. Maybe the JDBC test suite would meet your needs.
antonysequeira: I am trying to write a class (call it SQLOb) to closely bind objects to DB
columns. So when I call `next' on a SQLOb, it calls next on the resultSet (which is a member of it). Then it moves contents of columns to bound objects. It works for StringBuffer (I call setlength(0) followed by append(resultset.getString(i))
The problem with types like int, double, etc. is that the original reference is lost if I call new. Using Integer is no help, since it has no member function to set a value. It can't subclass since it is final. I suppose
this is actually a generic Java question, but I would appreciate an answer.
SPK-markhapner: Your problem is not quite clear from your question. As you note, the Java integer, double, etc. types are immutable. If you need to allocate something
to hold an int, and then set the value later--you can use your own type.
drkuykendall: I would like to hear from other developers about the books they recommend for JDBC development. (Solaris examples are a plus.)
SPK-markhapner: We recently published a JDBC book ourselves: JDBC Database
Access with Java, which is a good reference for JDBC and provides a
basic tutorial. Since JDBC is a reasonably simple API, the major challenge
is to understand SQL. So a good SQL book is also useful.
chamness: How do I find out the number of columns in a table? Currently, the examples I see are: ResultSet rs= Statement.executeQuery("select * from table");
ResultSetMetaData rsmd= rs.getMetaData()
int numColumns=rsmd.getColumnCount();
But why do I have to "select * from table"?
I don't want to select everything.
SPK-seth1: The DatabaseMetaData.getColumns() method can return meta information about each column. This method returns a resultSet
with one row per column, so the number of rows in the resultSet
equals the number of columns in the table.
MDR-andreaw: While Mark and Seth are typing, I'd like to make the last call for sending in questions.
drkuykendall: I am looking for a flat file implementation of a JDBC database server
to test with.
SPK-markhapner: Intersolv provides a Dbase4 ODBC driver that reads/writes Dbase files.
You could use this with the bridge. Many people are using MS Access.
Another good choice is to use SQL Anywhere from Sybase.
drkuykendall: I have a follow up to the flat file question: those do not run on Solaris. Are there any Solaris solutions?
SPK-markhapner: Intersolv does provide a version of the Dbase4 ODBC driver for Solaris.
JoeSam: I have a few comments. IBM has released a beta `AS/400 Toolbox for Java' (all client-side) which includes a JDBC driver. I just got it, and so can't
say how well it works yet. Also, I have written a JDBC/ODBC app/applet
which does work with HotJavaTM. I can't speak for other browsers, since the app is JDK 1.1-based.
SPK-seth1: That's a good thing to point out. HotJava can be configured to allow
applets to call native code, so the JDBC-ODBC bridge can be used by
applets running in HotJava. I don't know of other browsers that have that
capability, but any browser that does can be used with the bridge.
chamness: Is ResultSet.close() required after every query?
SPK-markhapner: Close is optional. If the same statement is used to produce several ResultSets, it will automatically close the old one when the new one is created.
Penumbra: We need a central database for our persistance issues. For performance reasons, we need to be able to download different portions of the database from the server to individual clients. Once the data is on the client side, we would like to continue to use Java database controls to access the (now
local) database. Is this possible? Is this involved? Is it expensive? Is there a better way?
SPK-seth1: I don't know of any all-Java database engines that are on the market today
that do this.
We are adding a rowset interface to JDBC that allows the results of a
query to be cached outside of the database. The rowset object can be
serialized using Java Object Serialization and sent anywhere on the
Net. It can also be updated, and its contents resynchronized with the database later. Maybe that would be useful for you when it is
available.
MDR-andreaw: Thank you for joining us. If you have more questions about JDBC,
check out the tutorial on the Java Developer Connection web site, or look
for information on the JavaSoft web site (java.sun.com/products/jdbc). Be sure to join us next week, for a discussion of PersonalJava.