我试图在maven项目中使用jdbc连接到Amazon Athena,但是正在引发异常。我认为这个课程没有找到。在雅典娜的指南中,它说:
- 将JDBC属性aws_credentials_provider_class设置为等于类名,并将其包含在类路径中。 (1)
醇>
由于我使用eclipse,我认为该类已经在类路径中,但显然不是。我在一个简单的java项目(不是maven)中测试了代码并且它可以工作。
AmazonCredentialsProvider.java :
package athena;
import com.amazonaws.auth.AWSCredentials;
public class AmazonCredentials implements AWSCredentials {
@Override public String getAWSAccessKeyId() { return "..."; }
@Override public String getAWSSecretKey() { return "..."; }
}
AmazonCredentialsProvider.java :
package athena;
import com.amazonaws.auth.AWSCredentials;
import com.amazonaws.auth.AWSCredentialsProvider;
public class AmazonCredentialsProvider implements AWSCredentialsProvider {
@Override public AWSCredentials getCredentials() { return new AmazonCredentials(); }
@Override public void refresh() {}
}
连接的代码段:
Class.forName("com.amazonaws.athena.jdbc.AthenaDriver");
Properties properties = new Properties();
properties.setProperty("user", user);
properties.setProperty("password", password);
properties.setProperty("aws_credentials_provider_class", "athena.AmazonCredentialsProvider");
Connection connection = DriverManager.getConnection("jdbc:awsathena://athena." + region + ".amazonaws.com:443", properties);
例外:
java.sql.SQLException:无法加载AWS凭据提供程序类: athena.AmazonCredentials提供者 com.amazonaws.athena.jdbc.AthenaDriverPropertiesFactory.lambda $ parseProperties $ 2(AthenaDriverPropertiesFactory.java:52) 在 com.amazonaws.athena.jdbc.AthenaDriverPropertiesFactory.setClientConfigProperty(AthenaDriverPropertiesFactory.java:159) 在 com.amazonaws.athena.jdbc.AthenaDriverPropertiesFactory.parseProperties(AthenaDriverPropertiesFactory.java:40) 在 com.amazonaws.athena.jdbc.AthenaDriver.connect(AthenaDriver.java:110) 在java.sql.DriverManager.getConnection(未知来源)at java.sql.DriverManager.getConnection(未知来源)at athena.Athena。(Athena.java:94)at services.GraphService.verify(GraphService.java:194)at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)at sun.reflect.NativeMethodAccessorImpl.invoke(未知来源)at sun.reflect.DelegatingMethodAccessorImpl.invoke(未知来源)at java.lang.reflect.Method.invoke(未知来源)at org.glassfish.jersey.server.model.internal.ResourceMethodInvocationHandlerFactory.lambda $静态$ 0(ResourceMethodInvocationHandlerFactory.java:76) 在 org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher $ 1.run(AbstractJavaResourceMethodDispatcher.java:148) 在 org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher.invoke(AbstractJavaResourceMethodDispatcher.java:191) 在 org.glassfish.jersey.server.model.internal.JavaResourceMethodDispatcherProvider $ VoidOutInvoker.doDispatch(JavaResourceMethodDispatcherProvider.java:183) 在 org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher.dispatch(AbstractJavaResourceMethodDispatcher.java:103) 在 org.glassfish.jersey.server.model.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:493) 在 org.glassfish.jersey.server.model.ResourceMethodInvoker.lambda $ $申请0(ResourceMethodInvoker.java:405) 在 org.glassfish.jersey.server.ServerRuntime $ AsyncResponder $ 2 $ 1.run(ServerRuntime.java:843) 在org.glassfish.jersey.internal.Errors $ 1.call(Errors.java:272)at at org.glassfish.jersey.internal.Errors $ 1.call(Errors.java:268)at org.glassfish.jersey.internal.Errors.process(Errors.java:316)at org.glassfish.jersey.internal.Errors.process(Errors.java:298)at org.glassfish.jersey.internal.Errors.process(Errors.java:268)at org.glassfish.jersey.process.internal.RequestScope.runInScope(RequestScope.java:289) 在 org.glassfish.jersey.server.ServerRuntime $ AsyncResponder $ 2.run(ServerRuntime.java:838) 在java.util.concurrent.Executors $ RunnableAdapter.call(未知 来自)java.util.concurrent.FutureTask.run(未知来源)at java.util.concurrent.ThreadPoolExecutor.runWorker(未知来源)at java.util.concurrent.ThreadPoolExecutor $ Worker.run(未知来源)at java.lang.Thread.run(未知来源)引起: java.lang.ClassNotFoundException:athena.AmazonCredentialsProvider at java.net.URLClassLoader.findClass(未知来源)at java.lang.ClassLoader.loadClass(未知来源)at java.lang.ClassLoader.loadClass(未知来源)at java.lang.Class.forName0(Native Method)at java.lang.Class.forName(未知来源)at com.amazonaws.athena.jdbc.AthenaDriverPropertiesFactory.lambda $ parseProperties $ 2(AthenaDriverPropertiesFactory.java:44) ......还有31个
有谁知道如何解决它?
答案 0 :(得分:0)
您使用的是最新版本的JDBC驱动程序吗?
如果是,请尝试按照以下说明操作:
https://docs.aws.amazon.com/redshift/latest/mgmt/configure-jdbc-connection-with-maven.html