• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Resultset

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!!!
 
mister krabs
Posts: 13974
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ResultSet is an interface. Create your own class that implements ResultSet.
 
RAJESH
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!!!
 
Ranch Hand
Posts: 146
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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....
 
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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)
 
Sheriff
Posts: 3341
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
No prison can hold Chairface Chippendale. And on a totally different topic ... my stuff:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic