create table mybean (id int primary key, name varchar, age int) bla bla
bla....

//make a model
class MyBean implements Serializable {
 private String name;
 private int age;
}

//create your idataprovider

private class ResultSetDataProvider implements IDataProvider
{
private Connection c;

public ResultSetDataProvider (Connection _c){
c = _c;
}
public Iterator iterator(int start, int count) {
String query = "SELECT name, age FROM mybean LIMIT " + start + "," +  count;
PrepareStatement pq = c.createStatement(query );
ResultSet set = pq.executeQuery();
//make a list to carry your records via the bean to your datatable
List<MyBean > dataList = new LinkedList<MyBean>();
while(set.next()){
//create your bean for each record, hopefully JDBC 4 should soon be here
MyBean bean = new MyBean();
bean.setName(set.getString("name"));
bean.setAge(set.getInt("age"));
dataList.add(bean);
}
return dataList.iterator();
}
public int size() {
String countQ = "SELECT COUNT(ID) FROM TABLE";
PrepareStatement pq = c.createStatement(countQ);
ResultSet set = pq.executeQuery();
if(set.next())
return set.getInt(1);
else
return 0;
}
public IModel model(Object arg0) {
return new Model((MyBean)arg);
}
}

//i would not know if there is some other more efficient manner but this is
as simple enough
// and it works with DataView, Paging, DataTable

this should not be too hard, is it? or you need something else

On 8/23/07, dtoffe <[EMAIL PROTECTED]> wrote:
>
>
>     Uhh, well... yes, you are right.....
>
>     Excuse me but I fail to see how that could help to solve the problem I
> presented, please keep in mind that I'm not native english speaker and
> perhaps I'm not using the proper words, I'll try to explain that more
> precisely.
>
>     As I said in my previous post, I do my database queries in this way:
>
>     ResultSet rs = cs.executeQuery();
>
>     In fact, later I'll use a code generator to ease the task, but let's
> assume for simplicity that I get the result in a java.sql.ResultSet. But,
> as
> stated in the Wicket Extension Javadoc, I must create the DataTable
> instances in this way:
>
>     DataTable table = new DataTable("datatable", columns, new
> UserProvider(), 10);
>
>     Specifically, the third parameter must implement
> wicket.markup.repeater.data.IDataProvider; which ResultSet doesn't
> implement, so I must provide for a means to overcome this.
>
>     I didn't intended to mean that ResultSets are more generic that
> DataProviders. When I talked about a "general" way of handling ResultSet I
> tried to mean independently of whether I'm querying a Database Table,
> Stored
> Porcedure, with read-only or read-write cursors, uni or bi-directional,
> and
> so. I'm concerned about how well this will go in regard of sortable and
> pageable tables.
>
>     Perhaps there is a mean to do all that already in the Wicket library,
> but I havent found it yet. In the examples I've seen so far the "database"
> is represented by some kind of static list, like in the ContactsDatabase
> and
> ContactGenerator classes in the DataTable example, but I'm looking for a
> way
> of using data from queries to a database engine.
>
>     The way I see it, I'll have to develop a class which could perhaps
> extends ResultSet, or one of the RowSet implementations, and implements
> the
> IDataProvider interface, am I right on this one ??
>
> Thanks for your help !!
>
> Daniel
>
>
>
> igor.vaynberg wrote:
> >
> > actually idataprovider is more generic then resultset :)
> >
> > -igor
> >
> >
> > On 8/22/07, dtoffe <[EMAIL PROTECTED]> wrote:
> >>
> >> Hi !!
> >>
> >>     I've found this old thread:
> >>
> >>
> http://www.nabble.com/RE%3A-DataView-%28extensions%29-tf1287013.html#a3423281
> >>
> >>     If there are new or better ways to do this that came up after this
> >> thread, I'm also interested in knowing. Having a way of easily handling
> >> the database resultset and a list of the resultset headers (column
> >> titles) would be great, the more generic, the better.
> >>
> >> Thanks !!
> >>
> >> Daniel
> >>
> >
>
> --
> View this message in context:
> http://www.nabble.com/Question-regarding-old-post-%28ResultSet-and-DataTable%29-tf4314874.html#a12287761
> Sent from the Wicket - User mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>

Reply via email to