Java – sqlnestedexception: unable to create poolableconnectionfactory (user ‘< >‘ @ ServerIP ‘denied access (use password: Yes))
I have an openshift site that tries to connect to an external MySQL server Here is my code so far
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()); } } }
All my Dao classes extend BaseDao, so I don't need to enter 5-6 times
After some configuration, this can run on the local MySQL server I created a small application that sends me to index. When the array collected from the database is not empty or empty JSP, if it is empty or null, send me to about jsp.
Now in the local and external databases, I created a table with the same name, column 'Day' and inserted a value When I run it locally, it sends me to the index page, but when I run it through my openshift page, it sends me to the about page
This is in SSH / APP root / logs / jbossews Log (user name and ServerIP have been commented out):
Note: the server and login information are provided by openswift provided by opanshce
The Dao path is: openingstijdenservlet – > (static) serviceprovider – > otservice – > openingstijdendao (extended 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)
Solution
There is a problem with your voucher Try changing credentials or server configuration Any managed server must select "localhost" / "127.0.0.1" as the database host