privatefinalConfigPoolFrameworkconfigPoolFramework=ConfigBuilder.getConfigBuilder().build(); // returns a default configuration// You do not have to change all values, the remaining values are filled with default values.
privatevoidtestQuery(){
this.asyncMySQLPoolHandler.executeQueryAsync("SELECT * FROM `"+"yourTable"+"`;").whenComplete((cachedRowSet,throwable)->{
try{
finalCollection<String> collection=newArrayList<>();
while(cachedRowSet.next()){
collection.add(cachedRowSet.getString(1));
}
// now you can work with the cachedRowSetcachedRowSet.close();
}catch(finalSQLExceptionexception){
exception.printStackTrace();
}
});
}
ReturnExecuteQuery:
ExecuteQueryAsync:
publicinttestQueryResult(finalStringvalue){
try{
finalCachedRowSetresultSet=this.asyncMySQLPoolHandler.executeQueryAsync("SELECT `yourColumn` FROM `"+"yourTable"+"` WHERE `yourValue`= '"+this.asyncMySQLPoolHandler.removeSQLInjectionPossibility(value)+"';").join();
if(resultSet.last()){
finalinttest=resultSet.getInt("yourColumn");
resultSet.close();
// return your async request resultreturntest;
}else{
resultSet.close();
// return a custom result if your request has failedreturn-1;
}
}catch(finalSQLExceptionexception){
exception.printStackTrace();
}
return-1;
}
ExecuteQueryInstantLastResultAsync:
publicinttest(finalStringvalue){
finalIntegerresult=(Integer)this.asyncMySQLPoolHandler.executeQueryInstantLastResultAsync("SELECT `yourColumn` FROM `"+"yourTable"+"` WHERE `yourValue`= '"+this.asyncMySQLPoolHandler.removeSQLInjectionPossibility(value)+"';","yourColumn").join();
returnresult!=null?result:-1;
}
ExecuteQueryInstantFirstResultAsync:
publicinttest(finalStringvalue){
finalIntegerresult=(Integer)this.asyncMySQLPoolHandler.executeQueryInstantFirstResultAsync("SELECT `yourColumn` FROM `"+"yourTable"+"` WHERE `yourValue`= '"+this.asyncMySQLPoolHandler.removeSQLInjectionPossibility(value)+"';","yourColumn").join();
returnresult!=null?result:-1;
}
ExecuteQueryInstantLastResultAsBooleanAsync:
publicbooleantest(finalStringvalue){
returnthis.asyncMySQLPoolHandler.executeQueryInstantLastResultAsBooleanAsync("SELECT `yourColumn` FROM `"+"yourTable"+"` WHERE `yourValue`= '"+this.asyncMySQLPoolHandler.removeSQLInjectionPossibility(value)+"';","yourColumn").join();
}
ExecuteQueryInstantFirstResultAsBooleanAsync:
publicbooleantest(finalStringvalue){
returnthis.asyncMySQLPoolHandler.executeQueryInstantFirstResultAsBooleanAsync("SELECT `yourColumn` FROM `"+"yourTable"+"` WHERE `yourValue`= '"+this.asyncMySQLPoolHandler.removeSQLInjectionPossibility(value)+"';","yourColumn").join();
}
ExecuteQueryInstantNextResultAsync:
publicbooleantest(finalStringvalue){
returnthis.asyncMySQLPoolHandler.executeQueryInstantNextResultAsync("SELECT * FROM `"+"yourTable"+"` WHERE `yourValue`= '"+this.asyncMySQLPoolHandler.removeSQLInjectionPossibility(value)+"';").join();
}
ExecuteUpdate with Statement:
privatevoidtestUpdate(finalStringyourValue){
this.asyncMySQLPoolHandler.executeUpdateAsync("INSERT INTO `"+"yourTable"+"` SET `yourColumn` = '"+this.asyncMySQLPoolHandler.removeSQLInjectionPossibility(yourValue)+"';").whenComplete((aVoid,throwable)->{
//now you can work with the result
});
}
ExecuteUpdate with PreparedStatement:
privatevoidtestUpdate(finalString...value){
this.asyncMySQLPoolHandler.executeUpdatePreparedStatementAsync("INSERT INTO `"+"yourTable"+"` (value1, value2, value3, value4) VALUES (?, ?, ?, ?)",value1,value2,value3,value4).whenComplete((aVoid,throwable)->{
//now you can work with the result
});
}
About
An simplify library to create jdbc pools via HikariCP. The Statement/PreparedStatement methods are performed asynchronously