Re: The easiest framework for Java Database applications development
released for production use
Hi Everybody,
This is what code that needs to either process the result set as it is
fetched (e.g. larger data sets) or needs to do something more with the
data might look like. The necessary database resources will be
allocated and deallocated by the framework immediately prior to and
immediately after the call to echoToConsole. The choice to use
reflection rather than an interface was driven by the need to have any
number of database data processing calls in a single class. This is a
complete example that should compile and run with out any additional
hand written code (given the existence of the underlying database) and
with only the database driver jar and the yaorma jar.
Sorry I won't be able to post the complete example to the web site
tonight but I'll get it there as soon as I can.
Thanks again for all of your help and feedback,
John
----8<-----------------8<-----------------
package org.yaorma.examples.resultSetUser.main;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import org.yaorma.database.Data;
import org.yaorma.database.Database;
public class YaormaDataUserExample {
public static void main(String[] args) throws Exception {
new YaormaDataUserExample().exe();
}
public void exe() throws Exception {
// some configuration parameters
String dbDriverClassName = "oracle.jdbc.driver.OracleDriver";
String dbUrl = "jdbc:oracle:thin:@localhost:1521:orcl";
String dbUid = "guest";
String dbPwd = "guestpwd";
// get a connection
Class.forName(dbDriverClassName);
Connection conn = DriverManager.getConnection(dbUrl, dbUid, dbPwd);
// use yaorma to get the database data
String sqlString = "select * from test_table order by row_id";
Database.query(this, "echoToConsole", conn, sqlString);
// done
System.out.println("Done!");
}
public void echoToConsole(ResultSet rs) throws Exception {
while(rs.next()) {
System.out.print(rs.getString("row_id"));
System.out.print(rs.getString("message"));
System.out.print("\n");
// use the data in any way you choose here
}
}
}