A Simple Example: Running an SQL Query

In this example, you will run a simple SQL query across a table littleblackbook which looks like this:

id name address phone
1 Ally Antonioletti 826 Hume Crescent, Southampton 01670061244
2 Amy Atkinson 583 Atkinson Drive, Southampton 06312054624
3 Andrew Borley 354 Jackson Road, Edinburgh 01057075166
4 Charaka Chue Hong 750 Pearson Crescent, Southampton 09945916393
5 Dave Hardman 079 Borley Gardens, Winchester 06725558505
... ... ... ...

For example, the following SQL statement selects one row from the table littleblackbook:

select * from littleblackbook where id='3475'

and returns the following:

3475 James Antonioletti 163 Palansuriya Avenue, Winchester 008979852295

Implementation

The following steps show you how to write a Java client that creates a Grid Data Service (GDS), queries the database and prints out the results.

  1. Create a new directory examples/tutorials/clienttoolkit/. Within this directory, open a new Java class with a main method, called SimpleClient.java, for example. This class has to import the following client toolkit classes:
    import uk.org.ogsadai.client.toolkit.Response;
    import uk.org.ogsadai.client.toolkit.service.DataService;
    import uk.org.ogsadai.client.toolkit.wsrf.WSRFServiceFetcher;
    import uk.org.ogsadai.client.toolkit.activity.sql.SQLQuery;
    
  2. Before you can access the database you must connect to the Data Service with a given URL.

See examples/tutorials/clienttoolkit/SimpleExample.java for an example solution.