问题4:Method org.postgresql.jdbc4.Jdbc4Statement.setQueryTimeout(int) is not yet implemented.


异常出现场景:

在使用java操作postgresql数据库时。


出现原因:

Jdbc4Statement类里面的需要实现setQueryTimeout 方法,但此处没有实现。该方法是用来设置查询超时时间的。正常情况下是不会存在该问题的,除非此处使用的postgres驱动jar有问题(版本)。


查看项目lib目录:

此处引用了两个postgre的jar,其中一个必定存在问题(如图)。
问题4:Method org.postgresql.jdbc4.Jdbc4Statement.setQueryTimeout(int) is not yet implemented.
按照猜想,我们打开第二个jar包postgresql-8.4-701.jdbc4.jar里面,找到报错的类Jdbc4Statement 发现里面确实没有该setQueryTimeout 方法(如图)。
问题4:Method org.postgresql.jdbc4.Jdbc4Statement.setQueryTimeout(int) is not yet implemented.


解决:

果断删除项目中的第二个jar包postgresql-8.4-701.jdbc4.jar,保留第一个jar,重启项目 恢复正常。【注意:项目使用postgresql版本为10.6,此处驱动经验证可用】