?
Solved

RMI using JDBC to pass back a ResultSet

Posted on 2001-08-30
6
Medium Priority
?
1,054 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 9

Accepted Solution

by:
doronb earned 600 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
This video teaches viewers about errors in exception handling.
Suggested Courses
Course of the Month16 days, 8 hours left to enroll

862 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