简体   繁体   English

将Java应用程序连接到IBM Bluemix中的SQL数据库

[英]Connecting a Java application to an SQL database in IBM Bluemix

I have created a Bluemix app that has a small SQL Database. 我创建了一个具有小型SQL数据库的Bluemix应用程序。 I want to access the database from my site with API calls. 我想使用API​​调用从我的站点访问数据库。 I am new to Java so I used the starter code provided in the Liberty for Java runtime and followed the " tutorial " linked in the Bluemix Docs. 我是Java的新手,所以我使用了Liberty for Java运行时中提供的入门代码,并遵循了Bluemix Docs中链接的“ tutorial ”。 I copied only the SQLDBSample.java file from the tutorial. 我仅从教程中复制了SQLDBSample.java文件。

I am having a lot of trouble in getting the SQL connection code to run. 我在使SQL连接代码运行时遇到很多麻烦。 I kept the @WebServlet("/SQLDBSample") and am unable to get the code to run even if I go to myapp.mybluemix.net/SQLDBSample. 我保留了@WebServlet("/SQLDBSample") ,即使转到myapp.mybluemix.net/SQLDBSample.也无法使代码运行myapp.mybluemix.net/SQLDBSample. I just want to get API routes set up and be able to do AJAX calls within the site JavaScript. 我只想设置API路由并能够在站点JavaScript中进行AJAX调用。

Cloudant is not a SQL database. Cloudant不是SQL数据库。 If you want to use the SQLDB example, you need to bind your app to the "SQL Database" service, not to Cloudant. 如果要使用SQLDB示例,则需要将应用程序绑定到“ SQL数据库”服务,而不是Cloudant。

You can refer to the below link. 您可以参考以下链接。 It describes in detail about connectivity between java code and db2(sqldb), which explains various operations like binding to sqldb, examining vcap_services and more. 它详细描述了Java代码与db2(sqldb)之间的连接,并解释了各种操作,例如绑定到sqldb,检查vcap_services等。

http://www.ibm.com/developerworks/cloud/library/cl-sqldb-app/ http://www.ibm.com/developerworks/cloud/library/cl-sqldb-app/

Two options to help you get started with Java and Cloudant NoSQL DB. 有两个选项可帮助您开始使用Java和Cloudant NoSQL DB。

1) In the Bluemix UI, click on Catalog and create a Java Cloudant boilerplate. 1)在Bluemix UI中,单击Catalog并创建Java Cloudant样板。 After you create your application, you can download the starter code and learn it 创建应用程序后,您可以下载入门代码并学习它

2) Read Java and Cloudant NoSQL DB on Bluemix blog post by @Sai-Vennam which describes the auto-configuration in detail. 2) @ Sai-Vennam的Bluemix博客文章阅读Java和Cloudant NoSQL DB,其中详细描述了自动配置。

None of these answers ended up working for me. 这些答案都没有对我有用。 I found no real solution so I switched to Node.js and got it working in minutes. 我没有找到真正的解决方案,所以我切换到Node.js,并在几分钟之内使它正常工作。 I'd recommend using Node if you're using BlueMix. 如果您正在使用BlueMix,我建议您使用Node。 It's simpler. 更简单。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM