|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectlazyj.DBFunctions.DBConnection
public static final class DBFunctions.DBConnection
Wrapper around a raw database connection. You cannot create this object directly and you must free the connections properly otherwise
you will run in big trouble.
Here is a sample code:
// set the connection parameters
ExtProperties dbProp = new ExtProperties();
dbProp.set("driver", "org.postgresql.Driver"); // mandatory
dbProp.set("database", "somedb"); // mandatory
dbProp.set("host", "127.0.0.1"); // defaults to 127.0.0.1 if missing
dbProp.set("port", "5432"); // DB-dependend default if missing
dbProp.set("user", "username"); // recommended
dbProp.set("password", "*****"); // recommended
// you can also set here various other configuration options that the JDBC driver will look at
DBFunctions db = new DBFunctions(dbProp);
DBFunctions.DBConnection conn = db.getConnection();
if (conn==null) return;
Statement stat = null;
ResultSet rs = null;
try{
stat = conn.getConnection().createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
stat.execute(someQuery, Statement.NO_GENERATED_KEYS);
rs = stat.getResultSet();
// ..................
rs.close();
rs = null;
stat.close();
stat = null;
}
catch (Exception e){ ... }
finally{
if (rs!=null){
// close
try{
rs.close();
}
catch (Exception e){
}
}
if (stat!=null){
try{
stat.close();
}
catch (Exception e){
}
}
conn.free();
}
DBFunctions.DBFunctions(ExtProperties)| Method Summary | |
|---|---|
boolean |
canUse()
Find out if this connection is free to use |
void |
close()
Really close a connection to the database |
protected void |
finalize()
On object deallocation make sure that the connection is properly closed. |
boolean |
free()
Mark a previously used connection as free to be used by somebody else |
java.sql.Connection |
getConnection()
Get the established JDBC connection for direct access to the database. |
java.lang.String |
getDescription()
Get the current description |
void |
setDescription(java.lang.String description)
Set the description to an arbitrary string to be used when debugging a problem. |
boolean |
use()
Use this connection, by marking it as busy and setting the last access time to the current time. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Method Detail |
|---|
public final java.sql.Connection getConnection()
public final boolean canUse()
public final boolean use()
public final boolean free()
public final void close()
protected final void finalize()
finalize in class java.lang.Objectpublic void setDescription(java.lang.String description)
description - the description to setpublic java.lang.String getDescription()
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||