aspose file tools*
The moose likes JDBC 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
Bookmark "Resultset " Watch "Resultset " New topic
Author

Resultset

RAJESH
Greenhorn

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 ??
thanks!!!
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
RAJESH
Greenhorn

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 )..
thanks!!!
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 (rs.next()) {
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 !!
Regards,
Milind
RAJESH
Greenhorn

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 ..like...
"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....
Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
Hi,
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
prakash
(prak_m@yahoo.com)
Carl Trusiak
Sheriff

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();
rset.next()
....
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: http://aspose.com/file-tools
 
subject: Resultset