be.six.reports.data
Class Database

java.lang.Object
  extended by be.six.reports.data.Database

public class Database
extends java.lang.Object

The Database class represents a database. The connection parameters and driver are configured trough the java preferences API: http://java.sun.com/j2se/1.4.2/docs/guide/lang/preferences.html The specified database driver has to be available in the ClassPath.

Author:
Joren Six

Method Summary
 void close()
          closes the database connection
 DatabaseResult fetchData(java.lang.String sql)
           
 DatabaseResult fetchData(java.lang.String sql, java.util.List<java.lang.Object> parameters)
          Sets the parameters in parameters in order and fetches data using a prepared statement.
static Database getInstance()
           
 DatabaseResult queryWithOneParam(java.lang.String sql, java.lang.Object param)
          Queries the database with only one parameter.
 DatabaseResult testResult()
          testResult is used to test the database connection
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getInstance

public static Database getInstance()
Returns:
The only Database instance.

testResult

public DatabaseResult testResult()
                          throws java.sql.SQLException
testResult is used to test the database connection

Returns:
A DatabaseResult containing 1000 identities
Throws:
java.sql.SQLException - if something goes awry

fetchData

public DatabaseResult fetchData(java.lang.String sql)
                         throws java.sql.SQLException
Parameters:
sql - the select query to execute
Returns:
a DatabaseResult containing the
Throws:
java.sql.SQLException

fetchData

public DatabaseResult fetchData(java.lang.String sql,
                                java.util.List<java.lang.Object> parameters)
                         throws java.sql.SQLException
Sets the parameters in parameters in order and fetches data using a prepared statement.

Parameters:
sql - the sql with question mark parameters e.g. select * from table where id = ? and name like ?
parameters - a list of parameters e.g. [10,"%a name"]
Returns:
A DatabaseResult representing the result.
Throws:
java.sql.SQLException - when something goes awry.

close

public void close()
closes the database connection


queryWithOneParam

public DatabaseResult queryWithOneParam(java.lang.String sql,
                                        java.lang.Object param)
Queries the database with only one parameter.

Parameters:
sql - the SQL statement with one question mark parameter e.g. select * from table where id = ?
param - a parameter e.g. 10
Returns:
A DatabaseResult representing the result.