package spo.db;
import com.javaexchange.dbConnectionBroker.DbConnectionBroker;
import java.io.*;
import java.sql.*;
import java.util.Properties;
public class DBAccess
implements Serializable
{
public DBAccess()
throws SQLException
{
try
{
prop = new Properties();
prop.load(new FileInputStream("spo.properties"));
String s = prop.getProperty("db.driver");
String s1 = prop.getProperty("db.url");
String s2 = prop.getProperty("db.username");
String s3 = prop.getProperty("db.password");
int i = Integer.parseInt(prop.getProperty("db.min"));
int j = Integer.parseInt(prop.getProperty("db.max"));
String s4 = prop.getProperty("db.log");
double d = 0.01D;
myBroker = new DbConnectionBroker(s, s1, s2, s3, i, j, s4, d);
}
catch(IOException ioexception)
{
ioexception.printStackTrace();
System.err.println((new StringBuilder()).append("connection error").append(ioexception).toString());
System.exit(-1);
}
}
public static Connection getDBConnection()
throws SQLException
{
Connection connection1 = myBroker.getConnection();
if(connection1 == null)
throw new SQLException("Cannot allocate connection from database connection pool.");
else
return connection1;
}
public static void returnDBConnection(Connection connection1)
{
myBroker.freeConnection(connection1);
}
public static String returnID(Connection connection1)
{
int i = myBroker.idOfConnection(connection1);
return (new StringBuilder()).append("<h3>DbConnectionBroker</h3>Using connection ").append(i).append(" from connection pool<p>").toString();
}
public static synchronized int getSeqID(Connection connection1, String s)
throws SQLException
{
int i = Integer.parseInt(prop.getProperty("db.code"));
String s1 = prop.getProperty("db.seq");
if(i == 1)
try
{
File file = new File((new StringBuilder()).append(s1).append(s).append(".dat").toString());
BufferedReader bufferedreader = new BufferedReader(new FileReader(file));
int j = Integer.parseInt(bufferedreader.readLine());
j++;
bufferedreader.close();
PrintWriter printwriter = new PrintWriter(new FileOutputStream(file));
printwriter.println(j);
printwriter.flush();
printwriter.close();
return j;
}
catch(Exception exception)
{
throw new SQLException((new StringBuilder()).append(exception.getMessage()).append(": Cannot get ID from ").append(s).toString());
}
String s2 = (new StringBuilder()).append("select ").append(s).append(".nextval from dual").toString();
Statement statement1 = connection1.createStatement();
ResultSet resultset = statement1.executeQuery(s2);
if(!resultset.next())
{
throw new SQLException((new StringBuilder()).append("Error when tring to execute: ").append(s2).toString());
} else
{
int k = resultset.getInt(1);
resultset.close();
statement1.close();
return k;
}
}
private static DbConnectionBroker myBroker;
private Connection connection;
private Statement statement;
protected static Properties prop;
}
The above code are from DBAcess.java. I have try to make some modification to improve current connection pool. The modification are: -add a d detail log -add connection heading -more in info about database(source of db).
How to make those modification?