将 MobileFirst 应用程序与 sql 数据库连接

Connect MobileFirst Application with sql database

我使用 CLI 制作了新的应用程序 Mobilefirst 8.0。

我已经按照 Link 创建了 sql 适配器。

在项目的根文件夹(root folder/Utils)中添加 SQL 数据库文件是正确的,因为在 7.1 中我们必须在服务器文件夹下添加 sql 文件。

还在根文件夹中添加了 jdbc lib 文件。但是,当我尝试调用适配器时,日志中出现“调用过程时抛出异常:适配器中的 getAccountTransactions2:SampleAdapter SQL 连接创建失败”。

谁能告诉我我做错了什么。下面是我上传到驱动器中的代码。

Code here

编辑: 我明白你做了什么......你完全错了。您不能在应用程序中包含 "database file" 并期望适配器 "connect" 到此数据库。

这是一张图表:

[应用程序] ----> [mobilefirst 服务器][适配器] ---> [数据库].

应用程序向服务器发送请求以调用适配器,适配器将向数据库发送请求,然后响应传播回来,直到它到达发送原始请求的应用程序。

您需要 运行 您的数据库在实际服务器中,而不是在应用程序中。


Added SQL databse file in root folder of project (root folder/Utils) is this right coz in 7.1 we have to add sql file under server folder.

我假设您指的是连接器驱动程序...这是错误的。
在 v8.0 中,您将连接器作为 Maven 依赖项添加到适配器的 pom.xml 文件中。

了解 Maven 依赖项:

根据您的数据库类型,在 Maven 存储库站点中搜索连接器:http://search.maven.org/

找到它后,将其引用添加到 pom.xml 文件并重新构建您的适配器。

请确保为您的数据库添加正确的值,在 adapter.xml 文件中(URL 到数据库、用户名、密码、.. .).

例如 MySQL:

pom.xml

<dependencies>
    <dependency>
        <groupId>com.ibm.mfp</groupId>
        <artifactId>adapter-maven-api</artifactId>
        <scope>provided</scope>
        <version>[8.0.0,9.0.0)</version>
    </dependency>
    <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
        <version>5.1.6</version>
    </dependency>
</dependencies>

adapter.xml

...
...
<dataSourceDefinition>
    <driverClass>com.mysql.jdbc.Driver</driverClass>
    <url>jdbc:mysql://localhost:3306/mobilefirst_training</url>
    <user>mobilefirst</user>
    <password>mobilefirst</password>
</dataSourceDefinition>