我必須使用SQLite數據庫實現連接池和標準JDBC DAO。實現連接池的最簡單方法是重用數據庫連接以減少Web應用程序的開銷?這裏是我編碼:JDBC和連接池選項
package persistance;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class SQLite {
Connection conn = null;
Statement stat = null;
public SQLite(String path) {
String dbPath = path + "GTI525.db";
System.out.println(dbPath);
try {
Class.forName("org.sqlite.JDBC");
conn = DriverManager.getConnection("jdbc:sqlite:" + dbPath);
stat = conn.createStatement();
} catch (SQLException e) {
e.printStackTrace();
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
}
public ResultSet query(String sql) {
ResultSet rs = null;
try {
rs = stat.executeQuery(sql);
} catch (SQLException e) {
e.printStackTrace();
}
return rs;
}
}
最簡單的事情就是不要寫一個 –