我一直在尝试通过我的 SQL 适配器连接 MySQL,但我不断收到以下错误:
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]
我的适配器 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>
使用:
- 操作系统平台:Mac OSX 10.8
- Eclipse:Kepler 服务版本 1
- Worklight:版本 6 开发人员版
- MySQL:mysql-connector-java-5.1.28-bin.jar 1.6.0_65
最佳答案
看看下面的内容是否有帮助:
尝试使用“localhost”而不是“127.0.0.1”。
当您连接到“localhost”时,使用套接字连接器,但当您连接到“127.0.0.1”时,使用 TCP/IP 连接器 (source)。
从问题中的错误消息来看,TCP/IP 连接似乎存在一些问题...因此也请尝试使用“localhost”。
根据问题中评论讨论中粘贴的信息,您可以尝试这些解决方案:
- https://stackoverflow.com/questions/4788381/getting-cant-connect-through-socket-tmp-mysql-when-installing-mysql-on-m
- Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
- Mountain Lion: Can't connect to local MySQL server through socket '/tmp/mysql.sock'
- Can't connect to local MySQL server through socket tmp/mysql.sock
关于mysql - IBM Worklight - "Could not connect to database"错误消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20837404/