You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by df...@apache.org on 2009/11/06 15:30:07 UTC
svn commit: r833409 - /commons/proper/dbutils/trunk/xdocs/examples.xml
Author: dfabulich
Date: Fri Nov 6 14:30:07 2009
New Revision: 833409
URL: http://svn.apache.org/viewvc?rev=833409&view=rev
Log:
[DBUTILS-62] Fix example page according to Java 5 version
Submitted by: Julien Aymé
Modified:
commons/proper/dbutils/trunk/xdocs/examples.xml
Modified: commons/proper/dbutils/trunk/xdocs/examples.xml
URL: http://svn.apache.org/viewvc/commons/proper/dbutils/trunk/xdocs/examples.xml?rev=833409&r1=833408&r2=833409&view=diff
==============================================================================
--- commons/proper/dbutils/trunk/xdocs/examples.xml (original)
+++ commons/proper/dbutils/trunk/xdocs/examples.xml Fri Nov 6 14:30:07 2009
@@ -46,8 +46,8 @@
<![CDATA[
// Create a ResultSetHandler implementation to convert the
// first row into an Object[].
-ResultSetHandler h = new ResultSetHandler() {
- public Object handle(ResultSet rs) throws SQLException {
+ResultSetHandler<Object[]> h = new ResultSetHandler<Object[]>() {
+ public Object[] handle(ResultSet rs) throws SQLException {
if (!rs.next()) {
return null;
}
@@ -69,8 +69,8 @@
QueryRunner run = new QueryRunner(dataSource);
// Execute the query and get the results back from the handler
-Object[] result = (Object[]) run.query(
- "SELECT * FROM Person WHERE name=?", "John Doe", h);
+Object[] result = run.query(
+ "SELECT * FROM Person WHERE name=?", h, "John Doe");
]]>
</source>
@@ -82,15 +82,15 @@
</p>
<source>
<![CDATA[
-ResultSetHandler h = ... // Define a handler the same as above example
+ResultSetHandler<Object[]> h = ... // Define a handler the same as above example
// No DataSource so we must handle Connections manually
QueryRunner run = new QueryRunner();
Connection conn = ... // open a connection
try{
- Object[] result = (Object[]) run.query(
- conn, "SELECT * FROM Person WHERE name=?", "John Doe", h);
+ Object[] result = run.query(
+ conn, "SELECT * FROM Person WHERE name=?", h, "John Doe");
// do something with the result
} finally {
@@ -107,24 +107,25 @@
</p>
<source>
+<![CDATA[
QueryRunner run = new QueryRunner( dataSource );
try
{
- // Create an object array to hold the values to insert
- Object[] insertParams = {"John Doe", new Double( 1.82 )};
// Execute the SQL update statement and return the number of
// inserts that were made
int inserts = run.update( "INSERT INTO Person (name,height) VALUES (?,?)",
- insertParams );
+ "John Doe", 1.82 );
+ // The line before uses varargs and autoboxing to simplify the code
// Now it's time to rise to the occation...
- Object[] updateParams = {new Double( 2.05 ), "John Doe"};
int updates = run.update( "UPDATE Person SET height=? WHERE name=?",
- updateParams );
+ 2.05, "John Doe" );
+ // So does the line above
}
catch(SQLException sqle) {
// Handle it
}
+]]>
</source>
</section>
@@ -149,16 +150,18 @@
</p>
<source>
+<![CDATA[
QueryRunner run = new QueryRunner(dataSource);
// Use the BeanHandler implementation to convert the first
// ResultSet row into a Person JavaBean.
-ResultSetHandler h = new BeanHandler(Person.class);
+ResultSetHandler<Person> h = new BeanHandler(Person.class);
// Execute the SQL statement with one replacement parameter and
// return the results in a new Person object generated by the BeanHandler.
-Person p = (Person) run.query(
- "SELECT * FROM Person WHERE name=?", "John Doe", h);
+Person p = run.query(
+ "SELECT * FROM Person WHERE name=?", h, "John Doe");
+]]>
</source>
<p>
@@ -167,15 +170,17 @@
</p>
<source>
+<![CDATA[
QueryRunner run = new QueryRunner(dataSource);
// Use the BeanListHandler implementation to convert all
// ResultSet rows into a List of Person JavaBeans.
-ResultSetHandler h = new BeanListHandler(Person.class);
+ResultSetHandler<List<Person>> h = new BeanListHandler(Person.class);
// Execute the SQL statement and return the results in a List of
// Person objects generated by the BeanListHandler.
-List persons = (List) run.query("SELECT * FROM Person", h);
+List<Person> persons = run.query("SELECT * FROM Person", h);
+]]>
</source>
</section>