java – SQLNestedException:无法创建PoolableConnectionFactory(用户’<>'@ SERVERIP'拒绝访问(使用密码

我有一个OpenShift站点,它试图连接到外部MySQL服务器.下面是我到目前为止的代码.public class BaseDAO {static final String DB_DRIVER = com.mysql.jdbc.Driver;DataSource datasource;public BaseDAO() {Syste...

'@ SERVERIP'拒绝访问(使用密码' />

我有一个OpenShift站点,它试图连接到外部MySQL服务器.下面是我到目前为止的代码.

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.

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

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

注意:服务器和登录信息由OPANSHCE提供的OPENHIFT提供

DAO的路径是:OpeningsTijdenServlet – > (静态)ServiceProvider – > OTService – > 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)

解决方法:

您的凭证有问题.尝试更改凭据或服务器配置.
任何托管服务器都必须选择“localhost”/“127.0.0.1”作为数据库主机.

本文标题为:java – SQLNestedException:无法创建PoolableConnectionFactory(用户’<>'@ SERVERIP'拒绝访问(使用密码

基础教程推荐