SQLNestedException:无法创建PoolableConnectionFactory(用户访问被拒绝&#39;&lt; <用户名>&gt;&#39; @&#39;服务器&#39;(使用密码:是))

时间:2015-10-13 11:44:13

标签: java mysql jdbc

我正在尝试连接外部MySQL服务器的OpenShift站点。下面是我到目前为止的代码。

public class BaseDAO {
static final String DB_DRIVER = "com.mysql.jdbc.Driver";
DataSource datasource;


public BaseDAO() {
    System.out.println("+++++ " +Calendar.getInstance().getTime());
    try{
        InitialContext ic = new InitialContext();
        Context initialContext = (Context) ic.lookup("java:comp/env");
        datasource = (DataSource) initialContext.lookup("jdbc/MySQLDS");
        Class.forName(DB_DRIVER).newInstance();
    } catch(Exception e){
        e.printStackTrace();
        throw new RuntimeException(e.getCause());
    }
  }
}

我所有的DAO课程都扩展了BaseDAO,因此我不必输入所有这些5-6次。

经过一些配置后,这适用于本地MySQL服务器。我创建了一个小应用程序,当从数据库收集的数组不为空或不为空时,将我发送到index.jsp,如果它为空或为null,则将我发送到about.jsp。

现在在本地和外部数据库中,我创建了一个具有相同名称,列&#39; day&#39;并插入1个值。当我在本地运行时,它会将我发送到索引页面,但是当我通过我的OpenShift网页运行它时,它会将我发送到about页面。

这是在SSH / app-root / logs / jbossews.log中发现的错误(用户名和serverip已注释掉) :

注意:服务器和登录信息是由OPANSHIFT提供的

DAO的路径是:OpeningsTijdenServlet - &gt; (静态)ServiceProvider - &gt; OTService - &gt; OpeningsTijdenDAO(扩展BaseDAO)

INFO: Server startup in 10894 ms
+++++ Mon Oct 12 16:07:51 EDT 2015
org.apache.tomcat.dbcp.dbcp.SQLNestedException: Cannot create      PoolableConnectionFactory (Access denied for user '<<USERNAME>>'@'SERVERIP' (using password: YES))
    at org.apache.tomcat.dbcp.dbcp.BasicDataSource.createPoolableConnectionFactory(BasicDataSource.java:1551)
    at org.apache.tomcat.dbcp.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:1390)
    at org.apache.tomcat.dbcp.dbcp.BasicDataSource.getConnection(BasicDataSource.java:1046)
    at main.java.database.OpeningsTijdenDAO.selectTijden(OpeningsTijdenDAO.java:16)
    at main.java.database.OTService.getTijden(OTService.java:13)
    at main.java.servlets.GetTijdenServlet.doPost(GetTijdenServlet.java:17)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:646)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
    at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:501)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
    at org.apache.catalina.valves.RemoteIpValve.invoke(RemoteIpValve.java:683)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1042)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:607)
    at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:316)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
    at java.lang.Thread.run(Thread.java:745)
Caused by: java.sql.SQLException: Access denied for user '<<USERNAME>>'@'SERVERNAME' (using password: YES)
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1078)
    at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4187)
    at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4119)
    at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:927)

1 个答案:

答案 0 :(得分:0)

您的凭据有问题。尝试更改凭据或服务器配置。 您必须选择任何托管服务器&#34; localhost&#34; /&#34; 127.0.0.1&#34;作为您的数据库主机。