简体   繁体   中英

Connecting a Java application to an SQL database in IBM Bluemix

I have created a Bluemix app that has a small SQL Database. I want to access the database from my site with API calls. 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. I copied only the SQLDBSample.java file from the tutorial.

I am having a lot of trouble in getting the SQL connection code to run. I kept the @WebServlet("/SQLDBSample") and am unable to get the code to run even if I go to myapp.mybluemix.net/SQLDBSample. I just want to get API routes set up and be able to do AJAX calls within the site JavaScript.

Cloudant is not a SQL database. If you want to use the SQLDB example, you need to bind your app to the "SQL Database" service, not to 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.

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

Two options to help you get started with Java and Cloudant NoSQL DB.

1) In the Bluemix UI, click on Catalog and create a Java Cloudant boilerplate. 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.

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. I'd recommend using Node if you're using BlueMix. It's simpler.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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