Hi, I am accessing the database from the bean and getting a ResultSet object. My question is that how do i transfer this object to the servlet so that the search results could be displayed by the servlet onto an HTML page. Thanks Sagar
This is a well-known issue. I recommend you do a search here for ResultSet and you'll get back lots of helpful stuff. The main things you need to think about are how large your result set can be, and thus whether you need to split it into separate pages, and whether you are happy coding HTML into a servlet or whether you would prefer a templating or page-compiling solution. If your problem is simply one of how to get data out of a ResultSet, you just need to use the "next()" method for each row, then getString(), getObject() etc. as appropriate for each column.
I just ran into this problem recently. If you are using Jbuilder, they supply some classes which can help. In particular the way I handled this was to create a DataSetData object, is a disconnected type recordset which can be returned from a function. In the calling method I used a StorageResultSet which you can load the DataSetData into and then use like you would have the ResultSet. Something like: DataSetData myData = myEJBRemote.getDataSetData(); StorageResultSet mySet; myData.load(mySet); I'm not sure load is the actual method but it should be easy to find out. Then in your ejb: public DataSetData getDataSetData() { Database db = new Database(); QueryDataSet qds = new QueryDataSet(); DataSetData mySet; try{ String queryText = "SELECT * FROM " + table; db.setConnection(new ConnectionDescriptor(connection, user, " ", false, driver)); qds.setQuery(new QueryDescriptor(db, queryText, null, true, Load.ALL)); qds.open(); DataSetData data = DataSetData.extractDataSet(qds); return data; } Even though this uses JBuilder specific classes, it can still be deployed to any environment. I'm sure there are other ways, but this is the simplest and quickest way I could find.
The way which I have been following is by using helper classes. For example: my method in the bean is public helperObject getSomeData(param you pass){} The helperObject would have get and set methods for the fields you are trying to retrieve.In the bean the set methods would be used to set the values of result set.The servlet would call the getSomeData() method and use the get methods to get those values. This would work if you know the db structure and the fields you want to retrieve.
Post by:autobot
Do the next thing next. That’s a pretty good rule. Read the tiny ad, that’s a pretty good rule, too.
a bit of art, as a gift, the permaculture playing cards