Issue Details (XML | Word | Printable)

Key: DBUTILS-38
Type: Improvement Improvement
Status: Closed Closed
Resolution: Fixed
Priority: Minor Minor
Assignee: Dennis Lundberg
Reporter: David Portabella
Votes: 0
Watchers: 1
Operations

If you were logged in you would be able to see more operations.
Commons DbUtils

example documentation page, update query

Created: 30/May/07 07:43 AM   Updated: 16/Mar/08 10:48 PM
Return to search
Component/s: None
Affects Version/s: None
Fix Version/s: 1.2

Time Tracking:
Not Specified

Resolution Date: 16/Mar/08 10:48 PM


 Description  « Hide
Hello,

I came across DBUtils:
http://jakarta.apache.org/commons/dbutils/examples.html

and I found your contact email:
http://jakarta.apache.org/commons/dbutils/team-list.html

In this example page, you show how to query a db, and get a bean object:

QueryRunner run = new QueryRunner(dataSource);
ResultSetHandler h = new BeanHandler(Person.class);
Person p = (Person) run.query("SELECT * FROM Person WHERE name=?", "John Doe", h);

It would be great to show also that it can handle list of objects:

QueryRunner run = new QueryRunner(dataSource);
ResultSetHandler h = new BeanHandler(Person.class);
List list = (List) run.query("SELECT * FROM Person WHERE name=?", "John Doe", h); 
while (Person p : list)
  System.out.println(p);

or something like this.

More importantly, it is not obvious how to execute an update query, using a bean object.
I did not find it in the documentation.
Would it be something like this?

QueryRunner run = new QueryRunner(dataSource);
ResultSetHandler h = new BeanHandler(Person.class);
Person p = (Person) run.query("SELECT * FROM Person WHERE name=?", "John Doe", h); 
p.setName("new name");
run.update("UPDATE Person WHERE name = "John Doe", p);

Could you please add the correct example in your example documentation webpage?

Regards,
DAvid Portabella



 All   Comments   Work Log   Change History   Subversion Commits      Sort Order: Ascending order - Click to sort in descending order
Dennis Lundberg made changes - 16/Mar/08 09:43 PM
Field Original Value New Value
Description Hello,

I came across DBUtils:
http://jakarta.apache.org/commons/dbutils/examples.html

and I found your contact email:
http://jakarta.apache.org/commons/dbutils/team-list.html

In this example page, you show how to query a db, and get a bean object:

QueryRunner run = new QueryRunner(dataSource);
ResultSetHandler h = new BeanHandler(Person.class);
Person p = (Person) run.query("SELECT * FROM Person WHERE name=?", "John Doe", h);

It would be great to show also that it can handle list of objects:

QueryRunner run = new QueryRunner(dataSource);
ResultSetHandler h = new BeanHandler(Person.class);
List list = (List) run.query("SELECT * FROM Person WHERE name=?", "John Doe", h);
while (Person p : list)
  System.out.println(p);

or something like this.

More importantly, it is not obvious how to execute an update query, using a bean object.
I did not find it in the documentation.
Would it be something like this?

QueryRunner run = new QueryRunner(dataSource);
ResultSetHandler h = new BeanHandler(Person.class);
Person p = (Person) run.query("SELECT * FROM Person WHERE name=?", "John Doe", h);
p.setName("new name");
run.update("UPDATE Person WHERE name = "John Doe", p);

Could you please add the correct example in your example documentation webpage?


Regards,
DAvid Portabella
Hello,

I came across DBUtils:
http://jakarta.apache.org/commons/dbutils/examples.html

and I found your contact email:
http://jakarta.apache.org/commons/dbutils/team-list.html

In this example page, you show how to query a db, and get a bean object:

{code}
QueryRunner run = new QueryRunner(dataSource);
ResultSetHandler h = new BeanHandler(Person.class);
Person p = (Person) run.query("SELECT * FROM Person WHERE name=?", "John Doe", h);
{code}

It would be great to show also that it can handle list of objects:

{code}
QueryRunner run = new QueryRunner(dataSource);
ResultSetHandler h = new BeanHandler(Person.class);
List list = (List) run.query("SELECT * FROM Person WHERE name=?", "John Doe", h);
while (Person p : list)
  System.out.println(p);
{code}

or something like this.

More importantly, it is not obvious how to execute an update query, using a bean object.
I did not find it in the documentation.
Would it be something like this?

{code}
QueryRunner run = new QueryRunner(dataSource);
ResultSetHandler h = new BeanHandler(Person.class);
Person p = (Person) run.query("SELECT * FROM Person WHERE name=?", "John Doe", h);
p.setName("new name");
run.update("UPDATE Person WHERE name = "John Doe", p);
{code}

Could you please add the correct example in your example documentation webpage?


Regards,
DAvid Portabella
Dennis Lundberg added a comment - 16/Mar/08 10:48 PM
Fixed in r637681.

Dennis Lundberg made changes - 16/Mar/08 10:48 PM
Resolution Fixed [ 1 ]
Fix Version/s 1.2 [ 12312139 ]
Assignee Dennis Lundberg [ dennisl@apache.org ]
Status Open [ 1 ] Closed [ 6 ]
Repository Revision Date User Message
ASF #637681 Sun Mar 16 22:49:34 UTC 2008 dennisl [DBUTILS-38] example documentation page, update query.

- Add examples on how to insert and update data.
- Add an example on how to use the BeanListHandler to fetch a List of beans.
Files Changed
MODIFY /commons/proper/dbutils/trunk/xdocs/examples.xml