首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >红移JDBC41驱动程序初始化异常

红移JDBC41驱动程序初始化异常
EN

Stack Overflow用户
提问于 2015-06-24 03:07:16
回答 1查看 3K关注 0票数 3

我正在开发通过Redshift JDBC41驱动程序1.1.2.0002版连接到亚马逊网络服务Redshift实例的应用程序

当我使用main(.)方法运行应用程序时,一切正常,但是当我尝试从单元测试( TestNG和Junit)获得连接时-在DataSource初始化时得到异常。下面是Redshift客户端类:

代码语言:javascript
复制
import com.amazon.redshift.jdbc41.DataSource;
import com.mycompany.common.config.PropertiesHelper;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import java.io.IOException;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.Properties;

/**
*/
public class RedshiftDBClient {

private static final Logger logger = LogManager.getLogger(RedshiftDBClient.class);

private static RedshiftDBClient instance;

private DataSource dataSource;

private Properties properties;

private RedshiftDBClient() {
}

private void initDataSource() throws IOException {


    properties = PropertiesHelper.getProperties();

    dataSource = new DataSource();
    dataSource.setUserID(properties.getProperty("rs.db.username"));
    dataSource.setPassword(properties.getProperty("rs.db.password"));
    dataSource.setURL(properties.getProperty("rs.db.url"));
}

public static synchronized RedshiftDBClient getInstance() {

    if (instance == null) {
        instance = new RedshiftDBClient();
    }

    return instance;
}

private DataSource getDataSource() throws IOException {

    if (dataSource == null) {
        initDataSource();
    }

    return  dataSource;
}

public Connection getConnection() throws SQLException, IOException {
    return getDataSource().getConnection();
}
}

下面是我得到的错误:

代码语言:javascript
复制
    java.lang.ClassCastException: com.amazon.redshift.jdbc41.Driver cannot be cast to com.amazon.dsi.core.interfaces.IDriver
    at com.amazon.dsi.core.impl.DSIDriverFactory.createDriver(Unknown Source)
    at com.amazon.jdbc.common.AbstractDataSource.doInitialize(Unknown Source)
    at com.amazon.jdbc.common.AbstractDataSource.getSimbaConnection(Unknown Source)
    at com.amazon.jdbc.common.AbstractDataSource.getConnection(Unknown Source)
    at com.mycompany.util.RedshiftDBClient.getConnection(RedshiftDBClient.java:60)
    at com.mycompany.model.redshift.MatchSummaryModel.save(MatchSummaryModel.java:37)
    at com.mycompany.thrift_gen.matchmaking.MatchmakingServiceHandler.ReportMatchResults(MatchmakingServiceHandler.java:59)
    at com.mycompany.thrift_gen.matchmaking.MatchmakingClientProxy$Processor$ReportMatchResults.getResult(MatchmakingClientProxy.java:499)
    at com.mycompany.thrift_gen.matchmaking.MatchmakingClientProxy$Processor$ReportMatchResults.getResult(MatchmakingClientProxy.java:484)
    at org.apache.thrift.ProcessFunction.process(ProcessFunction.java:39)
    at org.apache.thrift.TBaseProcessor.process(TBaseProcessor.java:39)
    at org.apache.thrift.server.TThreadPoolServer$WorkerProcess.run(TThreadPoolServer.java:285)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)
11:23:55.276 [pool-2-thread-1] ERROR com.mycompany.thrift_gen.matchmaking.MatchmakingServiceHandler - Database exception
java.sql.SQLException: Error creating Driver, Driver class name incorrect.
    at com.amazon.jdbc.common.AbstractDataSource.doInitialize(Unknown Source) ~[RedshiftJDBC41-1.1.2.0002.jar:RedshiftJDBC_1.1.2.0002]
    at com.amazon.jdbc.common.AbstractDataSource.getSimbaConnection(Unknown Source) ~[RedshiftJDBC41-1.1.2.0002.jar:RedshiftJDBC_1.1.2.0002]
    at com.amazon.jdbc.common.AbstractDataSource.getConnection(Unknown Source) ~[RedshiftJDBC41-1.1.2.0002.jar:RedshiftJDBC_1.1.2.0002]
    at com.mycompany.util.RedshiftDBClient.getConnection(RedshiftDBClient.java:60) ~[classes/:?]
    at com.mycompany.model.redshift.MatchSummaryModel.save(MatchSummaryModel.java:37) ~[classes/:?]
    at com.mycompany.thrift_gen.matchmaking.MatchmakingServiceHandler.ReportMatchResults(MatchmakingServiceHandler.java:59) [classes/:?]
    at com.mycompany.thrift_gen.matchmaking.MatchmakingClientProxy$Processor$ReportMatchResults.getResult(MatchmakingClientProxy.java:499) [classes/:?]
    at com.mycompany.thrift_gen.matchmaking.MatchmakingClientProxy$Processor$ReportMatchResults.getResult(MatchmakingClientProxy.java:484) [classes/:?]
    at org.apache.thrift.ProcessFunction.process(ProcessFunction.java:39) [libthrift-0.9.2.jar:0.9.2]
    at org.apache.thrift.TBaseProcessor.process(TBaseProcessor.java:39) [libthrift-0.9.2.jar:0.9.2]
    at org.apache.thrift.server.TThreadPoolServer$WorkerProcess.run(TThreadPoolServer.java:285) [libthrift-0.9.2.jar:0.9.2]
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [?:1.8.0_45]
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [?:1.8.0_45]
    at java.lang.Thread.run(Thread.java:745) [?:1.8.0_45]
Caused by: com.amazon.support.exceptions.GeneralException: Error creating Driver, Driver class name incorrect.
    at com.amazon.dsi.core.impl.DSIDriverFactory.createDriver(Unknown Source) ~[RedshiftJDBC41-1.1.2.0002.jar:RedshiftJDBC_1.1.2.0002]
    ... 14 more

我能想到的唯一一件事就是类路径/类加载器出了问题。

EN

回答 1

Stack Overflow用户

发布于 2015-07-09 10:35:53

问题是因为我在类路径中有Postgres JDBC驱动程序。Redshift JDBC驱动程序实际上是Postgres JDBC驱动程序,带有一些额外的类,可能还进行了一些重构。我删除了Redshift驱动程序,并使用Postgres驱动程序访问这两个数据库,解决了这个问题。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/31011380

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档