Hi,
I am connecting Database with this class but I want to use LocalThread. How can I do it? Do I need another ThreadLocal class or should I edit this MainDao class? This is MainDAO class and I have got another class also. My project is inside of the MVC and I used only
servlet not framework nor anything. My code is here:
public class MainDAO {
public MainDAO() {
conn = makeConn();
//conn = new ThreadLocal();
}
static Connection conn = null;
// public static Connection getConnection() {
// return (Connection) conn.get();
// }
// Statement statement;
public Connection makeConn() {
// private static ThreadLocal conn = new ThreadLocal();
// public Object initialValue() {
try {
DaoProperties dp = DaoProperties.getInstance();
String driver = dp.getProperty("swallow.jdbc.driver");
String url = dp.getProperty("swallow.jdbc.url");
String user = dp.getProperty("swallow.jdbc.user");
String password = dp.getProperty("swallow.jdbc.password");
Class.forName(driver);
return DriverManager.getConnection(url, user, password);
} catch (Exception e) {
return null;
}
}
protected void finalize() {
if (conn != null) {
try {
conn.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
public void rollback() throws SQLException {
if (conn != null) {
conn.rollback();
conn.close();
}
}
public void commit() throws SQLException {
if (conn != null) {
conn.commit();
conn.close();
}
}
}
I comment out some parts because I am not sure how I use. Please help me...