I'm using function which execute more than one query. I want to make it faster and don't open connection after single one.
I'm using sql2o library to connect my java program with postgresql. ConnectionClass is based on Singleton pattern.
In this code connecton.open() function is call number of execute queries time.
public class ConnectionClass{
private static final ConnectionClass db = new ConnectionClass();
private final Sql2o sql2o;
private Connection connection;
private InfraTramDAO() {
sql2o = new Sql2o("jdbc:postgresql:...............");
}
private List<Map<String, Object>> queryToList(String query) {
List<Map<String, Object>> returnList = connection.createQuery(complexSql).executeAndFetchTable().asList();
return returnList;
}
}
public void makeObject(FileMapper fileMapper ) {
ConnectionClass db = ConnectionClass.getInstance();
db.setConnection(db.getSql2o().open());
universalCreator(fileMapper ); //function execute few queries
db.getConnection().close();
}
Did you try Batch? Look example here