j-ra
j-ra

Reputation: 81

How to insert data into my SQLDB service instance (Bluemix)

I have created an SQLDB service instance and bound it to my application. I have created some tables and need to load data into them. If I write an INSERT statement into RUN DDL, I receive a SQL -104 error. How can I INSERT SQL into my SQLDB service instance.

Upvotes: 0

Views: 215

Answers (3)

Carlos Ferreira
Carlos Ferreira

Reputation: 2078

Most people do initial database population or migrations when they deploy their application. Often these database commands are programming language specific. The poster didn't include the programming language. You can accomplish this two ways.

  1. Append a bash script that would call your database scripts that you uploaded. This project shows how you can call that bash script from within your manifest file as part of doing a CF Push.

  2. Some languages like offer a file type or service that will automatically get used to populate the database on initial deploy or when your migrate/synch the db. For example Python Django offers a "fixtures" file that will automatically take a JSON file and populate your database tables

Upvotes: 0

Ram Vennam
Ram Vennam

Reputation: 3546

s.executeUpdate("CREATE TABLE MYLIBRARY.MYTABLE (NAME VARCHAR(20), ID INTEGER)");
s.executeUpdate("INSERT INTO MYLIBRARY.MYTABLE (NAME, ID) VALUES ('BlueMix', 123)");

Full Code

Upvotes: 1

RandalAnders
RandalAnders

Reputation: 1441

If you're needing to run your SQL from an application then there are several examples (sample code included) of how to accomplish this at the site listed below:

http://www.ng.bluemix.net/docs/services/SQLDB/index.html#run-a-query-in-java

Additionally, you can execute SQL in the SQL Database Console by navigating to Manage -> Work with Database Objects. More information can be found here:

http://www.ng.bluemix.net/docs/services/SQLDB/index.html#sqldb_005

Upvotes: 1

Related Questions