Search code examples
javaactivejdbc

ActiveJDBC insert without prepared statement


I'm trying to use ActiveJDBC with a DB whose driver does not support the Connection.prepareStatement(String, String[]) method. I'm getting the following exception when trying to insert:

org.javalite.activejdbc.DBException: java.sql.SQLFeatureNotSupportedException: [DataDirect][OpenEdge JDBC Driver]Unsupported method: Connection.prepareStatement(String, String[]), query: INSERT INTO ...
    at com.ddtek.jdbc.openedgebase.ddb9.b(Unknown Source)
    at com.ddtek.jdbc.openedgebase.ddb9.a(Unknown Source)
    at com.ddtek.jdbc.openedgebase.ddb8.b(Unknown Source)
    at com.ddtek.jdbc.openedgebase.ddb8.a(Unknown Source)
    at com.ddtek.jdbc.openedgebase.BaseConnection.prepareStatement(Unknown Source)
    at org.javalite.activejdbc.DB.execInsert(DB.java:597)
    at org.javalite.activejdbc.Model.insert(Model.java:2618)
    at org.javalite.activejdbc.Model.save(Model.java:2552)
    at org.javalite.activejdbc.Model.saveIt(Model.java:2477)
    ...

Some other forms of prepareStatement are supported, e.g. prepareStatement (String), prepareStatement (String, int), etc.

Is there anything I can do to convince ActiveJDBC not to use the unsupported statement?


Solution

  • As you can see in the source , this is pretty much hard coded. So from the top of my mind you could either request a change in ActiveJDBC or go ahead wrapping your "flawed" Connection into a custom implementation and overriding this prepareStatement(String, String[])

    public PreparedStatement prepareStatement(String qry, String[] autoIdColumns) {
      return delegate.prepareStatement(qry);
    }
    

    Google returned some ideas for ConnectionWrapper implementations out there.