【问题标题】:IBM Worklight - How to configure URL element of a SQL adapter?IBM Worklight - 如何配置 SQL 适配器的 URL 元素?
【发布时间】:2013-11-20 09:51:40
【问题描述】:

我有一个使用 SQL 适配器从数据库中检索数据的应用程序。

这是我的场景:一台机器可能像一个“服务器”,其中有数据库和一个设备,它可能是“客户端”。如果我有一个机器和设备都连接的局域网,我必须如何设置adapter.xml才能连接到机器?

<?xml version="1.0" encoding="UTF-8"?>
<!--
    Licensed Materials - Property of IBM
    5725-G92 (C) Copyright IBM Corp. 2011, 2012. All Rights Reserved.
    US Government Users Restricted Rights - Use, duplication or
    disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
-->
<wl:adapter name="DbConnect"
    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>DbConnect</displayName>
    <description>DbConnect</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://localhost:3306/test</url>
                <user>root</user>
                <password>mysql</password>
            </dataSourceDefinition>
        </connectionPolicy>
        <loadConstraints maxConcurrentConnectionsPerNode="5" />
    </connectivity>

    <!-- Replace this with appropriate procedures -->
    <procedure name="remoteDbSize"/>
    <procedure name="getCanti"/>
    <procedure name="getCategorie"/>

</wl:adapter>

我想我改变了&lt;url&gt; 的值,而不是localhost,我必须用机器局域网上的IP 地址来编辑它。这样对吗?如果我想连接到远程机器(在这种情况下是真正的服务器),知道它是如何工作的也会很有趣。

【问题讨论】:

    标签: ibm-mobilefirst worklight-adapters


    【解决方案1】:

    我很难找到在适配器 XML 文件中使用 dataSourceDefinition 的充分理由。设置 dataSourceJNDIName 只是多一点工作,并且是在适配器中使用 DataSource 的正确方法。它将运行时细节与开发工件分开,它允许不同的开发人员或在不同的环境中使用不同的数据库服务器而无需更改代码,并且它可以从适配器 XML 文件中获取数据库密码。

    有关如何配置 JNDI 数据源并将其与 Worklight Test 服务器一起使用的示例,您可以查看this blog post

    如果您使用 dataSourceJNDIName,那么对于您使用的任何应用服务器,您的场景都是非常标准的 DataSource 配置。

    【讨论】:

      【解决方案2】:

      后端是本地的还是远程的,都没有关系。

      如果您打算使用 SQL 适配器连接到 SQL 后端,则适配器 XML 中的 URL 元素需要指向该数据库,而不仅仅是托管数据库的服务器的 IP 地址。

      示例:&lt;url&gt;jdbc:mysql://my-host-or-ip:3306/my-database&lt;/url&gt;

      阅读材料:

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2016-01-03
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多