PrepareStatement doesn't
By default, the Connection.PrepareStatement in JDBC does nothing. One can pass junk text and it will still succeed because it is only on the subsequent execute call that both the prepare and the execute are batched and sent to the DBMS. This can be frustrating sometimes if one just wants to prepare a statement to check if it will work. This can be achieved by setting the property deferPrepares to false in the properties object passed to the connection object. Seems to work only with the Type 4 driver:
Properties sp = new Properties();
sp.setProperty("user", args[0]);
sp.setProperty("password", args[1]);
sp.setProperty("alias", args[2]);
sp.setProperty("deferPrepares", "false");
// Connection
Class.forName("com.ibm.db2.jcc.DB2Driver");
System.out.println("Connecting with Type-4 driver...");
url = "jdbc:db2:"+ sp.getProperty("alias");
conn = DriverManager.getConnection(url,sp);
System.out.println("...Connected.");
Properties sp = new Properties();
sp.setProperty("user", args[0]);
sp.setProperty("password", args[1]);
sp.setProperty("alias", args[2]);
sp.setProperty("deferPrepares", "false");
// Connection
Class.forName("com.ibm.db2.jcc.DB2Driver");
System.out.println("Connecting with Type-4 driver...");
url = "jdbc:db2:"+ sp.getProperty("alias");
conn = DriverManager.getConnection(url,sp);
System.out.println("...Connected.");
Labels: deferPrepares deferred prepare preparedstatement parsing query jdbc database db2
