aspose file tools*
The moose likes JDBC and the fly likes JDBC API Tutorial - questions about the book Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "JDBC API Tutorial - questions about the book" Watch "JDBC API Tutorial - questions about the book" New topic
Author

JDBC API Tutorial - questions about the book

Greg Ostravich
Ranch Hand

Joined: Jul 11, 2002
Posts: 112
I have some questions about your book and the latest JDBC API:
1) Are there examples of BLOB usage in your book? I see you cover the BLOB and CLOB in the API book, but my challenge in using those was I could not find code examples outside of something specific to Oracle. I was trying to find examples for Access, SQL Server, and Sybase and wasn't successful. Is that because the API for BLOBs are technology or driver specific?
2) Do you have proxy examples in your applet example? That was useful to me when I was using JDBC calls to an SQL Server that did not reside on the same machine as my applet lived on. I was able to track down a way to do this through a proxy that Sybase provided but it wasn't intuitively obvious to the most casual observer.
3) In the section you talk about PreparedStatement, do you talk about how some drivers may run into performance problems without it? I had a friend working on a servlet and ran into some errors until I showed him the PreparedStatement and now it seems to run just fine.
4) What new information is available in the ResultSet?
5) Do you cover the proper place to put your driver in Applet and in J2EE deployments? For me that wasn't obvious either and that would be useful information to have. I ended up dinking around putting the jar in different directories until I got it right but it wasn't quick and easy.
Thanks for being here to answer questions about your book.


Greg Ostravich - SCPJ2
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15300
    
    6

These are some very good and valid questions. I really hope the Authors will take some time to answer these.


GenRocket - Experts at Building Test Data
Lasse Koskela
author
Sheriff

Joined: Jan 23, 2002
Posts: 11962
    
    5
Originally posted by Greg Ostravich:
3) In the section you talk about PreparedStatement, do you talk about how some drivers may run into performance problems without it? I had a friend working on a servlet and ran into some errors until I showed him the PreparedStatement and now it seems to run just fine.

I recently encountered another annoying error related to PreparedStatements; reaching the maximum number of open cursors in the database. I solved it easily by moving the PreparedStatement compilation to/from a loop, but this could've gone unnoticed even more easily as I had to make over 3500 inserts before the errors started. Having said that, I'd also like to hear to what degree are the use (and misuse) of PreparedStatements covered in the book (I'm feeling it's time to put the good old persuade-company-librarian mode on so I'll get to have a peek at the book ).


Author of Test Driven (2007) and Effective Unit Testing (2013) [Blog] [HowToAskQuestionsOnJavaRanch]
Peter den Haan
author
Ranch Hand

Joined: Apr 20, 2000
Posts: 3252
Originally posted by Lasse Koskela:
I recently encountered another annoying error related to PreparedStatements; reaching the maximum number of open cursors in the database. [...]
Mmmm. Oracle, I presume? This is usually caused by the failure to close some resource, e.g. a ResultSet or Statement. I haven't had any bad experiences with Oracle PreparedStatements yet.
- Peter
Ko Ko Naing
Ranch Hand

Joined: Jun 08, 2002
Posts: 3178
Originally posted by Greg Ostravich:

4) What new information is available in the ResultSet?

Just want to share sthing... from IBM's article on JDBC 3.0 API
To facilitate modifying the values of CLOB (Character Large OBject), BLOB (Binary Large OBject), and REF (SQL structured) types, the data type interfaces of the same names have been updated. It follows that, because we are now able to update the values of these types, the ResultSet interface has been revised to support updating columns of these types, including updating the ARRAY type as well.
A limitation of the JDBC 2 specification is that statements that return multiple results must have only one ResultSet open at any given time. As a part of the changes in JDBC 3.0, the specification allows the Statement interface to support multiple open ResultSets. It is important to note, however, that the execute() method still closes any ResultSets that were opened from a previous call to execute(). So, to support multiple open results, the Statement interface adds an overloaded version of the method getMoreResults(). The new form of the method takes an integer flag that specifies the behavior of previously opened ResultSets when the getResultSet() method is called.


Co-author of SCMAD Exam Guide, Author of JMADPlus
SCJP1.2, CCNA, SCWCD1.4, SCBCD1.3, SCMAD1.0, SCJA1.0, SCJP6.0
Lasse Koskela
author
Sheriff

Joined: Jan 23, 2002
Posts: 11962
    
    5
Originally posted by Peter den Haan:
Mmmm. Oracle, I presume?

Yep. Oracle and too many unclosed resources.
Maydene Fisher
Author
Greenhorn

Joined: Jul 22, 2003
Posts: 14
Originally posted by Greg Ostravich:
I have some questions about your book and the latest JDBC API:
1) Are there examples of BLOB usage in your book? I see you cover the BLOB and CLOB in the API book, but my challenge in using those was I could not find code examples outside of something specific to Oracle. I was trying to find examples for Access, SQL Server, and Sybase and wasn't successful. Is that because the API for BLOBs are technology or driver specific?
-----------------------------------------------------
-->Reply
JDBC 3.0 includes methods for modifying BLOB and CLOB values, so the book has code showing how to use those methods. We need to be neutral about databases, so we don't discuss how to use a particular one. The whole point of having a standard API like JDBC is to have dbs follow the standard, but unfortunately that does not always happen. The book includes several caveats about checking both what your driver and database support (using DatabaseMetaData methods) and also what syntax they expect for certain things (reading the documentation for your driver and db).
----------------------------------------------------------

2) Do you have proxy examples in your applet example? That was useful to me when I was using JDBC calls to an SQL Server that did not reside on the same machine as my applet lived on. I was able to track down a way to do this through a proxy that Sybase provided but it wasn't intuitively obvious to the most casual observer.
---------------------------------------------------------
----->Reply
No. This is outside the purview of the book.
-------------------------------------------
3) In the section you talk about PreparedStatement, do you talk about how some drivers may run into performance problems without it? I had a friend working on a servlet and ran into some errors until I showed him the PreparedStatement and now it seems to run just fine.
--------------------------------------------
----->Reply
Yes. We mention the performance advantages of PreparedStatement objects in several places, including the chapter on the PreparedStatement interface.
--------------------------------------------
4) What new information is available in the ResultSet?
--------------------------------------------
----->Reply
There are various additions relating to ResultSet objects:
- new ResultSet method for retrieving an SQL DATALINK value (getUrl)
- new ResultSet constants for the ability to hold cursors over a commit
- new ResultSet methods for updating Ref, Blob, Clob, and Array objects
- new Statement constants for the ability to keep multiple ResultSet
objects returned from a stored procedure open at the same time
- new Statement method for returning a ResultSet object from a stored
procedure indicating whether it should remain open when another ResultSet
object is retrieved
- Statement method to find out whether the cursor of a ResultSet object
that is generated by the statement persists after the method commit is
called
--------------------------------------------------------
5) Do you cover the proper place to put your driver in Applet and in J2EE deployments? For me that wasn't obvious either and that would be useful information to have. I ended up dinking around putting the jar in different directories until I got it right but it wasn't quick and easy.
---------------------------------------------------------
----->Reply
This topic is really outside of the scope of the book. We do mention the
JDBC Connector, which makes it possible for a JDBC driver to be easily
plugged into any J2EE application server when both adhere to the Connector
specification.
-----------------------------------------------------------
Thanks for being here to answer questions about your book.


Hi Greg,
Please note the answers to your questions after each question. I hope I provided the information you were after.
Cheers,
Maydene


Maydene Fisher<br />author, "JDBC(tm) API Tutorial and Reference, Third Edition"
Maydene Fisher
Author
Greenhorn

Joined: Jul 22, 2003
Posts: 14
Originally posted by Lasse Koskela:

I recently encountered another annoying error related to PreparedStatements; reaching the maximum number of open cursors in the database. I solved it easily by moving the PreparedStatement compilation to/from a loop, but this could've gone unnoticed even more easily as I had to make over 3500 inserts before the errors started. Having said that, I'd also like to hear to what degree are the use (and misuse) of PreparedStatements covered in the book (I'm feeling it's time to put the good old persuade-company-librarian mode on so I'll get to have a peek at the book ).

Hi Lasse,
As Peter den Haan said in his reply to you, your problem may well be failing to close a resource, such as a ResultSet or Statement object. The book points out that it is good practice to close an object as soon as you are finished with it even though you know it will be automatically closed later. It is always good to release resources as soon as possible.
Cheers,
Maydene
Ko Ko Naing
Ranch Hand

Joined: Jun 08, 2002
Posts: 3178
Wow! That's tremendous... I have already copied and save it in my HD for the future use...
Lasse Koskela
author
Sheriff

Joined: Jan 23, 2002
Posts: 11962
    
    5
Originally posted by Maydene Fisher:
As Peter den Haan said in his reply to you, your problem may well be failing to close a resource, such as a ResultSet or Statement object.

Thanks Maydene,
Although the problem was that I prepareStatement()'d the SQL template for each loop separately (the code was close to beautiful, thanks to my refactoring urge, but...). I did close the statement object right after executeUpdate() but that wasn't enough. The problem only disappeared when I started reusing the PreparedStatement object.
Greg Ostravich
Ranch Hand

Joined: Jul 11, 2002
Posts: 112
Thanks Maydene for your replies.
I can understand why you don't include DB specific examples in your book but for the BLOB and CLOB stuff it would be nice because when I tried to do this using the JDBC 2 API I couldn't find examples on how to construct my BLOBs. There are examples of calls that show how to get a BLOB from the database, but not how to create one for storage into a database. If there's a generic way to do it, then that would be great to see in a book. If not, then listing a few of the technology examples would be nice too.
Thanks again for listing the new stuff in the ResultSet. That was a great description.
It's too bad you don't list where to put the Driver Jars though - if you have an example that's an applet you use in the book, it might make sense to tell the users where to put their driver jar.
Thanks for your replies - I look forward to checking out your book!
It sounds really great.
Greg
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JDBC API Tutorial - questions about the book