9

I am upgrading my project to Spring 5 and I noticed that it no longer has org.springframework.jdbc.support.nativejdbc package. We use SimpleNativeJdbcExtractor to extract native JDBC Connection. Sure I simply can use source code from Spring 4 and embed it into my project however I'd prefer to rely on a well established library.

Spring Framework web site only says that the packages are removed and doesn't offer any alternatives. Search through Spring 5 source code yields nothing. I wonder if anyone here can offer a suggestion on what the alternatives could be.

oᴉɹǝɥɔ
  • 1,796
  • 1
  • 18
  • 31

1 Answers1

5

I assume the reason you want access to the native java.sql.Connection is because you want access to a vendor connection class so you have access to vendor extensions. If that is the case you can simply use #unwrap(Class) eg

OracleConnection oracleConnection = connection.unwrap(OraleConnection.class);
Philippe Marschall
  • 4,452
  • 1
  • 34
  • 52
  • Thanks Phillipe but source code in Spring 4 does that and much more which brings me back to copying code from Spring 4 – oᴉɹǝɥɔ Nov 20 '17 at 17:25
  • @Kayaman that is a very valid point indeed. It is supposed(!) to work that way. The second comment on the ticket however points out that it is not always the case in the real world. The guy comes to the same conclusion as I do to use source code from the deprecated package – oᴉɹǝɥɔ Nov 20 '17 at 20:50
  • @oᴉɹǝɥɔ That's probably Oracle specific, again. Of all the problems I've seen related to JDBC drivers, it seems Oracle and MSSQL (the official one) are the worst. It could be that they tested it on different DBs and there was no problems, so they dropped it without realising it destroys performance on Oracle. You might want to comment on the ticket there to raise awareness. – Kayaman Nov 21 '17 at 06:07
  • `#unwarp(Class)` is portable and JDBC API since Java 1.6 / JDBC 4.0. With portable I mean works with every application server, connection pool and JDBC driver that is compliant. In addition it is also type safe. You only need this in case you want to access vendor exceptions. I would be very interested to see an actual profiling, I can't imagine how a simple method call that does a class check is noticeably more expensive than doing a reflective call when accessing the database. – Philippe Marschall Nov 21 '17 at 19:03