Meaningless Drivel is fun!*
The moose likes JBoss/WildFly and the fly likes can't connect to mysql datasource in jboss Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Products » JBoss/WildFly
Bookmark "can Watch "can New topic

can't connect to mysql datasource in jboss

Tom Esposito

Joined: Jul 28, 2009
Posts: 9
Ok, I can usually find a fix to my issues by browsing these forums but this time I'm stumped.

I set up a mysql database on a solaris box and set up a database for authorizing subversion users from my apache server. I got apache to authenticate against the database using dbd with the params: DBDParams "host=localhost port=19000 user=username pass=password dbname=subversion sock=/tmp/mysql.sock" (I'm using a custom port for this database). This works just fine, but I found that I needed to specify the sock to make the connection.

Now onto the jboss jdbc issue...

I created a quick java web app with the intention of maintaining users to my repository and am serving it from a jboss server running on the same machine.

MySQL version: 5.1.36
Jboss version: 4.2.2.GA

I set up my mysql-ds.xml by copying the example from jboss, dropped it in $JBOSS_HOME/server/default/deploy and filled in my params:
<!-- should only be used on drivers after 3.22.1 with "ping" support
<!-- sql to call when connection is created
<new-connection-sql>some arbitrary sql</new-connection-sql>
<!-- sql to call on an existing pooled connection when it is obtained from pool - MySQLValidConnectionChecker is
preferred for newer drivers
<check-valid-connection-sql>some arbitrary sql</check-valid-connection-sql>

<!-- corresponding type-mapping in the standardjbosscmp-jdbc.xml -->

But now when i try to run an action that creates a connection I get a Connection refused error. I tried adding the param: localSocketAddress=/tmp/mysql.sock because of the issue I had with apache with requiring the sock param and got a path not found exception because I'm sure my syntax was wrong. Any thoughts?

Stack Trace:
13:44:15,166 WARN [JBossManagedConnectionPool] Throwable while attempting to get a new connection: null
org.jboss.resource.JBossResourceException: Could not create connection; - nested throwable: (com.mysql.jdbc.CommunicationsException: Communications link failure

Last packet sent to the server was 0 ms ago.)
at org.jboss.resource.adapter.jdbc.local.LocalManagedConnectionFactory.createManagedConnection(
at org.jboss.resource.connectionmanager.InternalManagedConnectionPool.createConnectionEventListener(
at org.jboss.resource.connectionmanager.InternalManagedConnectionPool.getConnection(
at org.jboss.resource.connectionmanager.JBossManagedConnectionPool$BasePool.getConnection(
at org.jboss.resource.connectionmanager.BaseConnectionManager2.getManagedConnection(
at org.jboss.resource.connectionmanager.TxConnectionManager.getManagedConnection(
at org.jboss.resource.connectionmanager.BaseConnectionManager2.allocateConnection(
at org.jboss.resource.connectionmanager.BaseConnectionManager2$ConnectionManagerProxy.allocateConnection(
at org.jboss.resource.adapter.jdbc.WrapperDataSource.getConnection(
at com.exelon.eam.svn.dao.mysql.AbstractDAO.getConnection(
at com.exelon.eam.svn.dao.mysql.UserDAOMySQL.authorizeUser(
at com.exelon.eam.svn.manager.UserManager.authorizeUser(
at com.exelon.eam.svn.web.action.LoginAction.doExecute(
at com.exelon.eam.svn.web.action.AbstractAction.execute(
at org.apache.struts.chain.commands.servlet.ExecuteAction.execute(
at org.apache.struts.chain.commands.AbstractExecuteAction.execute(
at org.apache.struts.chain.commands.ActionCommandBase.execute(
at org.apache.commons.chain.impl.ChainBase.execute(
at org.apache.commons.chain.generic.LookupCommand.execute(
at org.apache.commons.chain.impl.ChainBase.execute(
at org.apache.struts.chain.ComposableRequestProcessor.process(
at org.apache.struts.action.ActionServlet.process(
at org.apache.struts.action.ActionServlet.doPost(
at javax.servlet.http.HttpServlet.service(
at javax.servlet.http.HttpServlet.service(
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(
at org.apache.catalina.core.ApplicationFilterChain.doFilter(
at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(
at org.apache.catalina.core.ApplicationFilterChain.doFilter(
at org.apache.catalina.core.StandardWrapperValve.invoke(
at org.apache.catalina.core.StandardContextValve.invoke(
at org.apache.catalina.core.StandardHostValve.invoke(
at org.apache.catalina.valves.ErrorReportValve.invoke(
at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(
at org.apache.catalina.core.StandardEngineValve.invoke(
at org.apache.catalina.connector.CoyoteAdapter.service(
at org.apache.coyote.http11.Http11Processor.process(
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(
Caused by: com.mysql.jdbc.CommunicationsException: Communications link failure

Last packet sent to the server was 0 ms ago.
at com.mysql.jdbc.SQLError.createCommunicationsException(
at com.mysql.jdbc.ConnectionImpl.createNewIO(
at com.mysql.jdbc.ConnectionImpl.<init>(
at com.mysql.jdbc.ConnectionImpl.getInstance(
at com.mysql.jdbc.NonRegisteringDriver.connect(
at org.jboss.resource.adapter.jdbc.local.LocalManagedConnectionFactory.createManagedConnection(
... 42 more
Caused by: Connection refused
at Method)
at com.mysql.jdbc.StandardSocketFactory.connect(
at com.mysql.jdbc.MysqlIO.<init>(
at com.mysql.jdbc.ConnectionImpl.createNewIO(
... 46 more
13:44:15,171 INFO [STDOUT] Could not create connection; - nested throwable: (com.mysql.jdbc.CommunicationsException: Communications link failure

Last packet sent to the server was 0 ms ago.); - nested throwable: (org.jboss.resource.JBossResourceException: Could not create connection; - nested throwable: (com.mysql.jdbc.CommunicationsException: Communications link failure

Thanks for any help!
Jaikiran Pai

Joined: Jul 20, 2005
Posts: 9937

Are you sure the port number of MySQL database is correct:

What does

return on the machine where you are having this issue?

[My Blog] [JavaRanch Journal]
Tom Esposito

Joined: Jul 28, 2009
Posts: 9
Oh wow - you were right!

I know when I set up my db I specified port=19000 (mysqld --port=19000 &) and when I run apache with the port specified as 19000 it works, but the telnet showed connection refused so I ran a quick "mysqladmin variables" and it showed my port as 3306 - so I reset my url to jdbc:mysql://localhost:3306/subversion. I don't know why apache would still work with the lookup port set at 19000 unless it automatically reverts to default on error...

The point is it worked - and I cant believe I didn't think of that before.

Thanks again for the help!!
wood burning stoves
subject: can't connect to mysql datasource in jboss
Similar Threads
Unable to deploy EJB application to JBoss when implementing persistence
can i add two different ds.xml files in jboss
problems connecting to remote db thru jdbc app
Problem oin connecting Oracle database in JBOSS AS 4.2.3
Need help to setup datasource for AS/400