Solved

RMI using JDBC to pass back a ResultSet

Posted on 2001-08-30
6
959 Views
Last Modified: 2007-11-27
I'm trying to make an RMI database object so the client can just pass an sql to the server and the server object will return a ResultSet record.  Is this possible? Basically I'm trying to remove any need for JDBC on the client side.

Thanks.
0
Comment
Question by:kllewelyn
6 Comments
 
LVL 9

Expert Comment

by:doronb
ID: 6441683
Hi,


I've done exactly the same thing, only in my implementation, the client doesn't even know anything about the SQL's running in the DB. The client simply sends requests through an RMI component which then translates these requests to SQL queries which are executed through JDBC by the RMI component. Instead of passing ResultSets I pass Vectors or Hashtables as responses. The client simply uses the RMI-DB component as just another component w/o knowing there's even a DB behind the scenes.


Doron
0
 
LVL 19

Expert Comment

by:Jim Cakalic
ID: 6441700
You might want to consider using the CachedRowSet -- one of the JDBC RowSet interface implementations from Sun. It is specifically intended for the purposes of "send a set of rows across a network" and "send data to a thin client". The client receiving the RowSet accesses it like a ResultSet (which RowSet extends). As such, it doesn't completely eliminate JDBC from the client but eliminates the database access that would normally occur when using JDBC calls.

Jim
0
 
LVL 1

Author Comment

by:kllewelyn
ID: 6441720
doronb, so the Vector that gets passed back then need to be manipulated on the client side to view the contents correctly? How do you handle the Vector once the client receives it?  I'm wanting to take the Vector/Recordset and toss it into a JTable to display the results.
0
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
LVL 9

Accepted Solution

by:
doronb earned 200 total points
ID: 6441849
You build a model using the Vector contents and display it in a JTable..

Actually, I'm not using just a simple Vector, but some objects I've developed in order to let the client be as thin as possible and yet modify the DB(INSERT/UPDATE/DELETE) with simple objects (just plain data memebers), more complex objects (objects containing references to other objects) and list objects (containing lists of either simple or complex objects).

These objects are wrapped with a JTable model and are edited by wizards we've developed. This lets me have something like an EJB client/server architecture but w/o a complex client or having to work with an Application Server.


Doron
0
 
LVL 4

Expert Comment

by:pellep
ID: 6441891
kllewelyn>>

Just a clarification. You cannot pass a ResultSet over an RMI connection. The immediate reason beeing that ResultSets are not serializable. As you may or may not know, RMI uses the JAVA serialization functionality in order to pass objects between server and client. The main reason why you can't serialize a resultset is because it holds internal references and state information about the original connection to the DB.

By default, most JDBC drivers doesn't populate a resultset, but rather maintains a cursor used to fetch information from the db as you're traversing the resultset (rs.next()). This cursor is only valid in the open session (ie connection) to the db.

Because of this you have to actully fetch all the data from the resultset move it to a serializable structure (ie Vector, HashMap or a custom object structure).

doronb gave you the proper sollution. I just thought I'd try and clarify the reason. If you need more help/clarification, don't hesitate to ask

Good luck
0
 
LVL 19

Expert Comment

by:Jim Cakalic
ID: 6442102
Or, as I indicated, use a CachedRowSet to achieve serializability of a ResultSet. If you already intend to construct a collection of data objects using the ResultSet at the client, then doing so on the server is no additional implementation overhead. But if you would really rather have a ResultSet-like object on the client then CachedRowSet would allow you to send the query results without the intermediate data-object and collection building.

Looks like I forgot the link in my first post (sorry):
    http://developer.java.sun.com/developer/earlyAccess/crs/

Jim

0

Featured Post

ScreenConnect 6.0 Free Trial

Want empowering updates? You're in the right place! Discover new features in ScreenConnect 6.0, based on partner feedback, to keep you business operating smoothly and optimally (the way it should be). Explore all of the extras and enhancements for yourself!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
stackato and cloud 4 86
servlet  URL Rewriting 1 37
Which non-HTML GUI front end to use with Java? 3 22
Adding multiple JVM environments to RedHat 6 7 23
For customizing the look of your lightweight component and making it look opaque like it was made of plastic.  This tip assumes your component to be of rectangular shape and completely opaque.   (CODE)
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
This video teaches viewers about errors in exception handling.

803 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question