0

I am trying to connect to mariadb from java - however i keep getting the following exception

com.ninja_squad.dbsetup.DbSetupRuntimeException: org.apache.commons.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory (Could not connect to 178.62.47.82:3306 : Connection refused)
    at com.ninja_squad.dbsetup.DbSetup.launch(DbSetup.java:123)
    at com.swiped.database.DBFactoryTest.setUp(DBFactoryTest.java:42)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
    at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:24)
    at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
    at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)
Caused by: org.apache.commons.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory (Could not connect to 178.62.47.82:3306 : Connection refused)
    at org.apache.commons.dbcp.BasicDataSource.createPoolableConnectionFactory(BasicDataSource.java:1549)
    at org.apache.commons.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:1388)
    at org.apache.commons.dbcp.BasicDataSource.getConnection(BasicDataSource.java:1044)
    at com.ninja_squad.dbsetup.destination.DataSourceDestination.getConnection(DataSourceDestination.java:80)
    at com.ninja_squad.dbsetup.DbSetup.launch(DbSetup.java:104)
    ... 24 more
Caused by: java.sql.SQLNonTransientConnectionException: Could not connect to 178.62.47.82:3306 : Connection refused
    at org.mariadb.jdbc.internal.SQLExceptionMapper.get(SQLExceptionMapper.java:136)
    at org.mariadb.jdbc.internal.SQLExceptionMapper.throwException(SQLExceptionMapper.java:106)
    at org.mariadb.jdbc.Driver.connect(Driver.java:114)
    at org.apache.commons.dbcp.DriverConnectionFactory.createConnection(DriverConnectionFactory.java:38)
    at org.apache.commons.dbcp.PoolableConnectionFactory.makeObject(PoolableConnectionFactory.java:582)
    at org.apache.commons.dbcp.BasicDataSource.validateConnectionFactory(BasicDataSource.java:1556)
    at org.apache.commons.dbcp.BasicDataSource.createPoolableConnectionFactory(BasicDataSource.java:1545)
    ... 28 more
Caused by: org.mariadb.jdbc.internal.common.QueryException: Could not connect to 178.62.47.82:3306 : Connection refused
    at org.mariadb.jdbc.internal.mysql.MySQLProtocol.connect(MySQLProtocol.java:677)
    at org.mariadb.jdbc.internal.mysql.MySQLProtocol.<init>(MySQLProtocol.java:266)
    at org.mariadb.jdbc.Driver.connect(Driver.java:110)
    ... 32 more
Caused by: java.net.ConnectException: Connection refused
    at java.net.PlainSocketImpl.socketConnect(Native Method)
    at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:339)
    at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:200)
    at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:182)
    at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
    at java.net.Socket.connect(Socket.java:579)
    at java.net.Socket.connect(Socket.java:528)
    at org.mariadb.jdbc.internal.mysql.MySQLProtocol.connect(MySQLProtocol.java:372)
    at org.mariadb.jdbc.internal.mysql.MySQLProtocol.connect(MySQLProtocol.java:673)
    ... 34 more

My JDBC connection string looks as follows;

jdbc:mariadb://178.62.47.82:3306/swiped", "username", "pass");

Whats strange is - I can connect to the database using mysql developer with the settings below

MYSQL-Workbench

Does anyone know if there is a particular format my connection string needs to be in or any other configuration that might be needed? I also have the following in my pom.xml

<dependency>
    <groupId>org.mariadb.jdbc</groupId>
    <artifactId>mariadb-java-client</artifactId>
    <version>1.1.7</version>
</dependency>
Biscuit128
  • 5,218
  • 22
  • 89
  • 149
  • Is the java application running on the same machine as the database? – Joachim Isaksson Jul 23 '14 at 18:44
  • at the moment it isn't - as i am trying to run from eclipse – Biscuit128 Jul 23 '14 at 18:53
  • that doesn't work - i used it earlier – Biscuit128 Jul 23 '14 at 19:29
  • 1
    Honestly sounds like a firewall problem. Your mysql developer connection runs (via SSH) from the local machine of the database, while the java connection does not. If the firewall blocks the port, it's quite possible that you'd be able to connect from mysql developer but not the external machine the java application runs on. – Joachim Isaksson Jul 23 '14 at 19:31
  • Hi Joachim indeed you were correct after posting on another forum I was able to get some help on resolving what you identified. Thank you very much for your help. Shame someone decided to close this post in case someone misses these comments – Biscuit128 Jul 24 '14 at 06:53

0 Answers0