Exception while using jtds for SqlServer connectivity

浪子不回头ぞ 提交于 2019-12-11 06:52:38

问题


I am using jtds driver to connect to SQLServer from a UnixBox using windows authentication from a SpringBoot+JPA application. Its a standalone application and not a WebBased application. I am successfully able to connect to the same but when I try to save some data using JPARepository, I receive the following exception :

java.lang.AbstractMethodError: null
at net.sourceforge.jtds.jdbc.JtdsPreparedStatement.setCharacterStream(JtdsPreparedStatement.java:1274) ~[jtds-1.3.1.jar:1.3.1]

I checked the corresponding source code in JtdsPreparedStatement and found that there is no implementation for this method :

@Override
public void setCharacterStream(int parameterIndex, Reader reader,
        long length) throws SQLException {
    // TODO Auto-generated method stub
    throw new AbstractMethodError();
}

As suggested here; we can implement the same and it is supposed to work. Can someone please explain how can I register my implementation of JtdsPreparedStatement to be picked at runtime by the Spring container and not the default one ? or if there is any other option available ?

Edit : JtdsPreparedStatement has a constructor with default scope; Can't even extend it


回答1:


There is an open jTDS bug for this. In short, the JDBC standards specifies two different methods for setting character stream:

Old method signature:

public void setCharacterStream(int parameterIndex, Reader reader, long length) throws SQLException

New method signature:

public void setCharacterStream(int parameterIndex, Reader reader, int length) throws SQLException

With the difference being the last parameter that was changed from long to int.

jTDS haven't implemented the new method, which is used by Hibernate, and therefore you get the AbstractMethodError.

You have 2 options here:

  1. Switch to Microsoft JDBC driver, which supports this method
  2. Get the sources code of jTDS and implement the method yourself (most likely by forwarding the old method to the new method)

From my experience, don't count on an official release anytime soon.



来源:https://stackoverflow.com/questions/39658960/exception-while-using-jtds-for-sqlserver-connectivity

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!