Statement Caching
Each physical connection to the server will have its own Statement cache. Statements are cached with a key. For implicit caching the key used is the SQL string used for the Statement. For an explicit cache, you can specific the key you want to save the Statement with.
Enabling Statement Caching
Connection conn = Driver.getConnection("jdbc:onedb://localhost:9889/testdb;user=onedbsa;password=password; IFX_PREPAREDSTATEMENT_CACHE_SIZE=20"); ((IfxConnection)conn).setStatementCacheSize(20); // Can set the cache size at any time on the connection
Explicitly Statement Caching
You can explicitly save a statement into the case with a specified key. You must have already enabled the cache on the parent Connection object. You can then close any PreparedStatement or CallableStatement with closeWithKey(String uniqueKey). This caches the statement with your key instead of the SQL statement.
PreparedStatment p = conn.prepareStatement("SELECT * FROM systables"); ((IfxPreparedStatement)p).closeWithKey("sample-key"); p = ((IfxConnection)conn).getStatementWithKey("sample-key");
Disabling Caching for a single Statement
stmt.setPoolable(false); stmt.close();
Example
Properties prop = new Properties(); prop.setProperty("IFX_PREPAREDSTATEMENT_CACHE_SIZE", "20"); //save 20 prepared statements try(Connection con = DriverManager.getConnection(“JDBC-url-here", prop)) { try(PreparedStatement p = con.prepareStatement("INSERT INTO mytable VALUES(?)")) { //do work } //prepared statement closed/cached //SQL matches, so we get back the prepared statement handle to reuse try(PreparedStatement p = con.prepareStatement("INSERT INTO mytable VALUES(?)")) { //do work } //prepared statement closed/cached }