使用jtds进行SqlServer连接时出现异常 [英] Exception while using jtds for SqlServer connectivity

查看:1936
本文介绍了使用jtds进行SqlServer连接时出现异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用jtds驱动程序从SpringBoot + JPA应用程序使用Windows身份验证从UnixBox连接到SQLServer。它是一个独立的应用程序,而不是一个基于Web的应用程序。我成功地能够连接到相同的,但是当我尝试使用JPARepository保存一些数据时,我收到以下异常:

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

我在 JtdsPreparedStatement ,并发现这个方法没有实现:

  @Override 
public void setCharacterStream(int parameterIndex,Reader读取器,
长度)抛出SQLException {
// TODO自动生成的方法存根
throw new AbstractMethodError();
}

here ;我们可以执行相同的操作,它应该可以工作。有人能解释一下,我怎样才能注册我的 JtdsPreparedStatement 的实现,以便在运行时被Spring容器挑选出来而不是默认的?或者是否有其他选项可用?

编辑 JtdsPreparedStatement 有一个构造函数默认范围;甚至无法扩展它

解决方案

有一个开放 jTDS bug 。简而言之,JDBC标准指定了两种设置字符流的方法:

旧方法签名:

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

新方法签名:

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

差异是从long更改为int的最后一个参数。



jTDS尚未实现由Hibernate使用的新方法,因此您将得到AbstractMethodError。



您有2个选项:


  1. 切换到支持此方法的Microsoft JDBC驱动程序

  2. 获取jTDS的源代码并自己实现该方法(很可能通过将旧方法转发到新方法)

从我的经验,不要指望在任何时候正式发布。


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

解决方案

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.

这篇关于使用jtds进行SqlServer连接时出现异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆