Solved

RMI using JDBC to pass back a ResultSet

Posted on 2001-08-30
6
993 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

 
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

The Ultimate Checklist to Optimize Your Website

Websites are getting bigger and complicated by the day. Video, images, custom fonts are all great for showcasing your product/service. But the price to pay in terms of reduced page load times and ultimately, decreased sales, can lead to some difficult decisions about what to cut.

Question has a verified solution.

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

For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
The viewer will learn how to implement Singleton Design Pattern in Java.

729 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