3

I have been trying to connect MySQL via my SQL adapter but I keep getting the following error:

Could not connect to database. Cannot create PoolableConnectionFactory (Connection refused. Check that the hostname and port are correct and that the postmaster is accepting TCP/IP connections.). [project SampleWorklightApp]

My adapter XML:

<?xml version="1.0" encoding="UTF-8"?>
<wl:adapter name="sampleSQLAdapter" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xmlns:wl="http://www.worklight.com/integration" xmlns:sql="http://www.worklight.com/integration/sql">

  <displayName>sampleSQLAdapter</displayName>
  <description>sampleSQLAdapter</description>
  <connectivity>
    <connectionPolicy xsi:type="sql:SQLConnectionPolicy">
      <!-- Example for using a JNDI data source, replace with actual data 
        source name -->
      <!-- <dataSourceJNDIName>java:/data-source-jndi-name</dataSourceJNDIName> -->

      <!-- Example for using MySQL connector, do not forget to put the MySQL 
        connector library in the project's lib folder -->
      <dataSourceDefinition>
        <driverClass>com.mysql.jdbc.Driver</driverClass>
        <url>jdbc:mysql://127.0.0.1:3306/test</url>
        <user>root</user>
        <password>sanchit</password>
      </dataSourceDefinition>
    </connectionPolicy>
    <loadConstraints maxConcurrentConnectionsPerNode="5" />
  </connectivity>

  <!-- Replace this with appropriate procedures -->
  <procedure name="getCustomerName" />
  <procedure name="insertCustomerDetails" />
</wl:adapter>

Using:

  • OS Platform : Mac OSX 10.8
  • Eclipse:Kepler Service Release 1
  • Worklight: Version 6 Developer Edition
  • MySQL: mysql-connector-java-5.1.28-bin.jar 1.6.0_65
Idan Adar
  • 44,156
  • 13
  • 50
  • 89
Rahul Singh
  • 103
  • 1
  • 10
  • There are two ways to connect to mysql, on using networking (address and port) and one using socket files. Depending on how and which version of mysql you installed, networking is disabled (it is something like a security feature having mysql not reachable from outside by default), so the first steps are, check if mysql is running, then check if networking is active for mysql or change the connection type to use file socket instead. – t.niese Dec 30 '13 at 10:17
  • Double check the host (Try "localhost"...) port, database name, firewall settings (try disabling it). – Idan Adar Dec 30 '13 at 10:37
  • Also sometimes restarting the machine helps... try that too. – Idan Adar Dec 30 '13 at 10:39
  • @t.niese: MYSQL is running and also network is active for the MYSQL. I don't have idea regarding the socket file. Could you let me know how can I resolve it using socket files. – Rahul Singh Dec 31 '13 at 09:32
  • @idan Adar: I did tried restarting my machine but still not able to connect it.Could you guide me. – Rahul Singh Dec 31 '13 at 09:33
  • Double check the host (Try "localhost"...) port, database name, firewall settings (try disabling it). – Idan Adar Dec 31 '13 at 09:34
  • @RahulSingh how did you check that mysql is running and that it is listening on on port `3306`? Please check it e.g. using `sudo lsof -i -P | grep -i "mysqld"` in terminal. If mysql is listening on a port, you should then see something like this: `mysqld _mysql 36u IPv4 0t0 TCP *:3306 (LISTEN)` and on which `*:3306` – t.niese Dec 31 '13 at 09:51
  • Yes, I get the following message.When Trying to run mysql(mysql=/usr/local/mysql/bin/mysql) command,I get the following error:`ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)`.How can I fix it. – Rahul Singh Dec 31 '13 at 11:37
  • @RahulSingh: Did you manage to solve this problem with the help of answers and comments in here? If so, could you close this question or provide a follow up, please? – eabe Mar 26 '14 at 06:36

1 Answers1

0

See if the below helps:

  1. Try "localhost" instead of "127.0.0.1".

    When you connect to "localhost" the socket connector is used, but when you connect to "127.0.0.1" the TCP/IP connector is used (source).

    From your error message in the question there seems to be some problem with the TCP/IP connection... so try "localhost" as well.

  2. Based on the information pasted in the comments discussion in the question, you can try these solutions:

Community
  • 1
  • 1
Idan Adar
  • 44,156
  • 13
  • 50
  • 89