2

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?

ArtKorchagin
  • 4,801
  • 13
  • 42
  • 58
gimoh
  • 53
  • 4
  • The `String[]` is for auto-generated keys. Do you need the auto-generated key values returned? – lance-java Dec 01 '15 at 10:24
  • No, I don't. All I'm doing in the code is `m = new Model();`, populate it, then `m.saveIt();`, there are no autogenerated columns in the model. ActiveJDBC calls the `prepareStatement` method internally [here](https://github.com/javalite/activejdbc/blob/master/activejdbc/src/main/java/org/javalite/activejdbc/DB.java#L625) – gimoh Dec 01 '15 at 13:17
  • what database/driver are you using? – ipolevoy Dec 01 '15 at 17:42
  • I'm using an OpenEdge RDBMS and their proprietary driver `com.ddtek.jdbc.openedge.OpenEdgeDriver`, it's a legacy DB I have to interface with. – gimoh Dec 02 '15 at 20:41

2 Answers2

0

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.

Jan
  • 13,738
  • 3
  • 30
  • 55
  • How would I feed such wrapped Connection into AJ? Is that going to be something to do with using `Base.open(DataSource dataSource)`? – gimoh Dec 01 '15 at 12:19
  • I'm not that deep in AJ. But that seems about right - if you pass in DataSource then that DataSource will in turn create the connections. where do you get DataSource from? – Jan Dec 01 '15 at 12:20
  • No idea actually, I haven't used DataSoruces so far, it was the only thing I could see in AJ API that seemed it would allow overriding Connection. I'll dig into that, thanks @Jan – gimoh Dec 01 '15 at 12:35
  • See how to create a DataSouce here: https://github.com/javalite/activejdbc/blob/master/activejdbc/src/test/java/org/javalite/activejdbc/mock/MockDataSource.java and: https://github.com/javalite/activejdbc/blob/master/activejdbc/src/test/java/org/javalite/activejdbc/DataSourceTest.java – ipolevoy Dec 01 '15 at 17:41
0

Please, look at databases supported by ActiveJDBC: http://javalite.io/activejdbc#supported-databases. Each one is thoroughly tested.

ipolevoy
  • 5,432
  • 2
  • 31
  • 46