Solved

RMI using JDBC to pass back a ResultSet

Posted on 2001-08-30
6
932 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
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:

707 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now