File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JDBC and Relational Databases and the fly likes Resultset Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "Resultset " Watch "Resultset " New topic



Joined: Jan 20, 2002
Posts: 7
I have about 6 to 7 variables that I need to return to Client as a resultset from my EJB, is there any way we can create a ResultSet on a fly without going to database ??
Thomas Paul
mister krabs
Ranch Hand

Joined: May 05, 2000
Posts: 13974
ResultSet is an interface. Create your own class that implements ResultSet.

Associate Instructor - Hofstra University
Amazon Top 750 reviewer - Blog - Unresolved References - Book Review Blog

Joined: Jan 20, 2002
Posts: 7
I understand that ResultSet is a interface and I can create my own class which implements ResultSet. But can someone throw light on how to create columns and fill data ( I just need 1 row )..
Milind Kulkarni
Ranch Hand

Joined: Jun 01, 2000
Posts: 146
Hi Raj,
Here is how I would code:
Connection con = DriverManager.getConnection (url, userID, pswd);
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery(SQL query);
while ( {
System.out.println (rs.getString( col1);
System.out.println (rs.getString( col2);
// and so on ....

If you want to display column headings you may also use ResultSetMetaData object to retrive column headings.
Hope this helps !!

Joined: Jan 20, 2002
Posts: 7
Milind, thanks for response but this is not I am looking for. I think my original question is not clear enough, let me rephrase it ....
I have 6 values (as a result of a CreditCard transaction) that I need to return from my EJB. One of the client using my EJB is a Powerbuilder 6.5 App (which has to use MASP to talk to EJB), anyway, I need to return these values to PowerBuilder App as a ResultSet.
There is no SQL here nor I am going to any DB, the credit card transaction result values are returned by credit card authorizing server to EJB and EJB needs to send these values as a resultset.
I came up with an Idea, build a dummy SQL
"Select Var1, Var2, var3.....Var7"; and execute this as a SQL against a DB and I will get back a ResultSet with same values..
What I was looking for was to build a ResultSet class having a 6 columns ( one each for my variables that I need to return)...without having to go to any DB....
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
you can't send it as Resultset. you supposed to store in Vector, and you can send. let me know, if i'm unclear
with regards
Carl Trusiak

Joined: Jun 13, 2000
Posts: 3340
As Thomas said, create your own class that implements ResultSet.
public class DummyResultSet{
HashTable results = new HashTable();//this is used to store the results to mimic what ResultSet does
//you could use whatever classes of Collections that you need
//override the methods of ResultSet that you need to use in your other app
public static DummyResultSet resultSetFactory()
//in here you define the code that creates the DummyResultSet
//it might be a good idea to make the constrictor private
In your other programs call the factory and assisgn the return to a ResultSet reference
ResultSet rset = DummyResultSet.resultSetFactory();
Now if every you do put this information in a DB, you modify the factory to create an execute the SQL and comment out the methods that you have overridden to use the methods in the ResultSet interface.

I Hope This Helps
Carl Trusiak, SCJP2, SCWCD
I agree. Here's the link:
subject: Resultset
It's not a secret anymore!