This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
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


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Products » JBoss/WildFly
Bookmark "can Watch "can New topic
Author

can't connect to mysql datasource in jboss

Tom Esposito
Greenhorn

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:
<datasources>
<local-tx-datasource>
<jndi-name>jdbc/svnAdminDS</jndi-name>
<connection-url>jdbc:mysql://127.0.0.1:19000/subversion</connection-url>
<driver-class>com.mysql.jdbc.Driver</driver-class>
<user-name>username</user-name>
<password>password</password>
<min-pool-size>5</min-pool-size>
<max-pool-size>20</max-pool-size>
<exception-sorter-class-name>org.jboss.resource.adapter.jdbc.vendor.MySQLExceptionSorter</exception-sorter-class-
name>
<!-- should only be used on drivers after 3.22.1 with "ping" support
<valid-connection-checker-class-name>org.jboss.resource.adapter.jdbc.vendor.MySQLValidConnectionChecker</valid-co
nnection-checker-class-name>
-->
<!-- 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 -->
<metadata>
<type-mapping>mySQL</type-mapping>
</metadata>
</local-tx-datasource>
</datasources>


But now when i try to run an action that creates a connection I get a java.net.ConnectException: 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(LocalManagedConnectionFactory.java:179)
at org.jboss.resource.connectionmanager.InternalManagedConnectionPool.createConnectionEventListener(InternalManagedConnectionPool.java:577)
at org.jboss.resource.connectionmanager.InternalManagedConnectionPool.getConnection(InternalManagedConnectionPool.java:262)
at org.jboss.resource.connectionmanager.JBossManagedConnectionPool$BasePool.getConnection(JBossManagedConnectionPool.java:500)
at org.jboss.resource.connectionmanager.BaseConnectionManager2.getManagedConnection(BaseConnectionManager2.java:341)
at org.jboss.resource.connectionmanager.TxConnectionManager.getManagedConnection(TxConnectionManager.java:315)
at org.jboss.resource.connectionmanager.BaseConnectionManager2.allocateConnection(BaseConnectionManager2.java:396)
at org.jboss.resource.connectionmanager.BaseConnectionManager2$ConnectionManagerProxy.allocateConnection(BaseConnectionManager2.java:842)
at org.jboss.resource.adapter.jdbc.WrapperDataSource.getConnection(WrapperDataSource.java:88)
at com.exelon.eam.svn.dao.mysql.AbstractDAO.getConnection(AbstractDAO.java:39)
at com.exelon.eam.svn.dao.mysql.UserDAOMySQL.authorizeUser(UserDAOMySQL.java:40)
at com.exelon.eam.svn.manager.UserManager.authorizeUser(UserManager.java:35)
at com.exelon.eam.svn.web.action.LoginAction.doExecute(LoginAction.java:15)
at com.exelon.eam.svn.web.action.AbstractAction.execute(AbstractAction.java:14)
at org.apache.struts.chain.commands.servlet.ExecuteAction.execute(ExecuteAction.java:58)
at org.apache.struts.chain.commands.AbstractExecuteAction.execute(AbstractExecuteAction.java:67)
at org.apache.struts.chain.commands.ActionCommandBase.execute(ActionCommandBase.java:51)
at org.apache.commons.chain.impl.ChainBase.execute(ChainBase.java:190)
at org.apache.commons.chain.generic.LookupCommand.execute(LookupCommand.java:304)
at org.apache.commons.chain.impl.ChainBase.execute(ChainBase.java:190)
at org.apache.struts.chain.ComposableRequestProcessor.process(ComposableRequestProcessor.java:283)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1913)
at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:462)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:710)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:230)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:179)
at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:84)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:157)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:262)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:446)
at java.lang.Thread.run(Thread.java:595)
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(SQLError.java:1070)
at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2103)
at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:718)
at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:298)
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:282)
at org.jboss.resource.adapter.jdbc.local.LocalManagedConnectionFactory.createManagedConnection(LocalManagedConnectionFactory.java:171)
... 42 more
Caused by: java.net.ConnectException: Connection refused
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:333)
at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:195)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:182)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:366)
at java.net.Socket.connect(Socket.java:520)
at java.net.Socket.connect(Socket.java:470)
at java.net.Socket.<init>(Socket.java:367)
at java.net.Socket.<init>(Socket.java:209)
at com.mysql.jdbc.StandardSocketFactory.connect(StandardSocketFactory.java:253)
at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:280)
at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2026)
... 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
Marshal

Joined: Jul 20, 2005
Posts: 9913
    
158

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
Greenhorn

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!!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: can't connect to mysql datasource in jboss
 
Similar Threads
Unable to deploy EJB application to JBoss when implementing persistence
problems connecting to remote db thru jdbc app
Problem oin connecting Oracle database in JBOSS AS 4.2.3
can i add two different ds.xml files in jboss
Need help to setup datasource for AS/400