Hallo Zusammen
Ich möchte über einen Hikari Connection Pool Verbindung zu meiner Datenbank Herstellen. Dies habe ich auch geschafft und die Connection steht. Das Problem ist nur, dass ich sobald ich ein PreparedStatement ausführen möchte, dies nicht möglich ist über den Hikari Connection Pool.
Ich muss irgendetwas in der Configuration des Connection Pools ändern, ich habe schon Properties für den PreparedStatementCache hinzugefügt aber es funktioniert immer noch nicht. Hat jemand von euch eine Idee wie ich dieses Problem beheben kann.
Hier mein Code:
Hier aus Ausführen der Connection und der SQL Query mit einem PreparedStatement:
Freundliche Grüsse
Selmau
Ich möchte über einen Hikari Connection Pool Verbindung zu meiner Datenbank Herstellen. Dies habe ich auch geschafft und die Connection steht. Das Problem ist nur, dass ich sobald ich ein PreparedStatement ausführen möchte, dies nicht möglich ist über den Hikari Connection Pool.
Ich muss irgendetwas in der Configuration des Connection Pools ändern, ich habe schon Properties für den PreparedStatementCache hinzugefügt aber es funktioniert immer noch nicht. Hat jemand von euch eine Idee wie ich dieses Problem beheben kann.
Hier mein Code:
Code:
public class pool_connection {
private static final String DB_USERNAME="db.username";
private static final String DB_PASSWORD="db.password";
private static final String DB_URL ="db.url";
private static final String DB_DRIVER_CLASS="driver.class.name";
private static Properties properties = null;
private static HikariDataSource dataSource;
static{
try {
properties = new Properties();
properties.load(new FileInputStream("src/database.properties"));
dataSource = new HikariDataSource();
dataSource.setDriverClassName(properties.getProperty(DB_DRIVER_CLASS));
dataSource.setJdbcUrl(properties.getProperty(DB_URL));
dataSource.setUsername(properties.getProperty(DB_USERNAME));
dataSource.setPassword(properties.getProperty(DB_PASSWORD));
dataSource.setMinimumIdle(1);
dataSource.setMaximumPoolSize(2000);//The maximum number of connections, idle or busy, that can be present in the pool.
dataSource.addDataSourceProperty("cachePrepStmts", "true");
dataSource.addDataSourceProperty("prepStmtCacheSize","250");
dataSource.addDataSourceProperty("prepStmtCacheSqlLimit", "2048");
dataSource.addDataSourceProperty("useServerPrepStmts", "true");
dataSource.addDataSourceProperty("useLocalSessionState","true");
dataSource.addDataSourceProperty("useLocalTransactionState","true");
dataSource.addDataSourceProperty("rewriteBatchedStatements","true");
dataSource.addDataSourceProperty("cacheResultSetMetadata","true");
dataSource.addDataSourceProperty("cacheServerConfiguration","true");
dataSource.addDataSourceProperty("elideSetAutoCommits","true");
dataSource.addDataSourceProperty("maintainTimeStats","true");
} catch(Exception e) {
e.printStackTrace();
}
}
public static DataSource getDataSource(){
return dataSource;
}
}
Hier aus Ausführen der Connection und der SQL Query mit einem PreparedStatement:
Code:
try {
Connection connection = null;
connection = pool_connection.getDataSource().getConnection();
String query = "INSERT INTO `produkte_snf` (`product_id`, `Produkt`, `Preis`) VALUES ('88', 'test', '26.00') ";
PreparedStatement pst_insert=(PreparedStatement) connection.prepareStatement(query);
pst_insert.execute();
if (connection == null){
JOptionPane.showMessageDialog(null, "Keine Verbindung");
}
else{
JOptionPane.showMessageDialog(null, "Daten gesendet");}
}catch(Exception e) {
JOptionPane.showMessageDialog(null, "Fehler");
}
Freundliche Grüsse
Selmau