This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Resultset

 
RAJESH
Greenhorn
Posts: 7
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13974
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ResultSet is an interface. Create your own class that implements ResultSet.
 
RAJESH
Greenhorn
Posts: 7
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 146
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 7
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 18944
  • 0
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3340
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic