// Let's try DaoHelperForJndi, which creates
// PreparedStatement from JNDI DataSource.
// JNDI DataSource name must be available as the
// environment valuable.
String className="com.oopreserch.dao.DaoHelperForJndi";
SimpleDaoHelper helper
=DaoHelperFactory.getDaoHelper(className);
// Please specify your SQL statement here...
String select="SELECT id,name FROM example WHERE age > ?";
QueryData query=new QueryData(select);
// Specify the value to be set on the SQL statement.
query.addInt(20);
// Please specify the return type(s) as the int array.
// This int array must consist of the pre-defined int
// constants...
// The order is important!
int[] types={QueryData.INT, QueryData.STRING};
// Its time to execute your SQL statement...
List list=helper.select(query,types);
// The returned List includes the selected rows.
// You can iterate each row...
Iterator it=list.iterator();
while(it.hasNext()){
// Each object in the returned List is also the List.
// And this nested List object represents each row...
List row=(List)(it.next());
// Get the first column...
int id=(Integer)(row.get(0)).intValue();
// Get the second column...
String name=(String)(row.get(1));
}
|
Copyright © 1997-2007 OOP-Research CorporationTM, All Rights Reserved.