Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

  • Java Development Kit / JRE version 1.6.* or 1.7.*
  • Apache Ant 1.7.0 or later

Building the sample

Table of Contents

Introduction

This sample simply connect to a mysql server and execute a script which is located in the jar package and insert values into created database tables and retrieve data from values inserted from through the program.

Prerequisites

  • Java Development Kit / JRE version 1.6.* or 1.7.*
  • Apache Ant 1.7.0 or later

Building the sample

Code Block
languagehtml/xml
<data enableBoxcarring="true" name="RDBMSSample" serviceNamespace="http://ws.wso2.org/dataservice/samples/rdbms_sample">   
	<config id="default">
	  // add the database driver of the relevant db instance created.
      <property name="org.wso2.ws.dataservice.driver">com.mysql.jdbc.Driver</property>
	  //add the database url recieved from Storage server.
      <property name="org.wso2.ws.dataservice.protocol">jdbc:mysql://localhost:3306/devdb1</property>
	  //add a user to connecto to the database, which is already attached to the afore mentioned database via Storage Server.
      <property name="org.wso2.ws.dataservice.user">devuser1</property>
	  //use the aforementioned users password. 	
      <property name="org.wso2.ws.dataservice.password">devuser1</property>
      <property name="org.wso2.ws.dataservice.minpoolsize">1</property>
      <property name="org.wso2.ws.dataservice.maxpoolsize">10</property>
      <property name="org.wso2.ws.dataservice.autocommit">false</property>
      <property name="org.wso2.ws.dataservice.validation_query"/>
   </config>

   //The Query.
   <query id="customersInBostonSQL" useConfig="default">
      <sql>select  * from Customers where city = 'Boston' and country = 'USA'</sql>
      <result element="customers" rowName="customer">
         <element column="customerName" name="customer-name" xsdType="string"/>
         <element column="contactLastName" name="contact-last-name" xsdType="string"/>
         <element column="contactFirstName" name="contact-first-name" xsdType="string"/>
         <element column="phone" name="phone" xsdType="string"/>
         <element column="city" name="city" xsdType="string"/>
         <element column="country" name="country" xsdType="string"/>
      </result>
   </query>

	//The dataservice.
	<operation name="customersInBoston">
      <call-query href="customersInBostonSQL"/>
   </operation>
</data>
Code Block
languagebash
mvn clean assembly:assembly -o

Executing the sample

Code Block
languagebash
java -jar  -Djdbcurl=jdbc:mysql://localhost:3306/rssdb -Ddriver=com.mysql.jdbc.Driver -Dusername=root -Dpassword=root target/rss-simple-sql-sample-1.0-jar-with-dependencies.jar

 

  1. you can create a datasource
Code Block
languagehtml/xml
<data enableBoxcarring="true" name="RDBMSSample" serviceNamespace="http://ws.wso2.org/dataservice/samples/rdbms_sample">   
	<config id="default">
      <property name="org.wso2.ws.dataservice.driver">com.mysql.jdbc.Driver</property>
      <property name="org.wso2.ws.dataservice.protocol">jdbc:mysql://localhost:3306/devdb1</property>
      <property name="org.wso2.ws.dataservice.user">devuser1</property>
      <property name="org.wso2.ws.dataservice.password">devuser1</property>
      <property name="org.wso2.ws.dataservice.minpoolsize">1</property>
      <property name="org.wso2.ws.dataservice.maxpoolsize">10</property>
      <property name="org.wso2.ws.dataservice.autocommit">false</property>
      <property name="org.wso2.ws.dataservice.validation_query"/>
   </config>
   <query id="customersInBostonSQL" useConfig="default">
      <sql>select  * from Customers where city = 'Boston' and country = 'USA'</sql>
      <result element="customers" rowName="customer">
         <element column="customerName" name="customer-name" xsdType="string"/>
         <element column="contactLastName" name="contact-last-name" xsdType="string"/>
         <element column="contactFirstName" name="contact-first-name" xsdType="string"/>
         <element column="phone" name="phone" xsdType="string"/>
         <element column="city" name="city" xsdType="string"/>
         <element column="country" name="country" xsdType="string"/>
      </result>
   </query>
	<operation name="customersInBoston">
      <call-query href="customersInBostonSQL"/>
   </operation>
</data>
Code Block
languagebash
mvn clean assembly:assembly -o

Executing the sample

Code Block
languagebash
java -jar  -Djdbcurl=jdbc:mysql://localhost:3306/rssdb -Ddriver=com.mysql.jdbc.Driver -Dusername=root -Dpassword=root target/rss-simple-sql-sample-1.0-jar-with-dependencies.jar