2. Let's suppose you have a Database
The name of your Database is MyDB and it
contains one table called People
id name surname
1 John Smith
2 Donald Duck
You want to develop a Jolie service able to read
and to write from/into MyDB
3. Prepare libraries
Jolie connects databases through JDBC drivers.
Prepare the JDBC .jar library of your database
server as it follows:
lib
yourJDBCdriver.jar
your_service.ol
1) Create a folder named lib in the same path where
your jolie service is
2) Put the JDBC .jar driver into the folder lib
6. Create a query
Jolie is equipped with protection against SQL
injection. You can pass parameters to the query.
q = “select name from people where id>:id”;
q.id = 0;
Parameters in SQL queries
are prefixed with “:”
Parameters values are
passed as message fields
query@Database( q )( result );
7. Get the result
Rows are listed in subvector row where
subfields are column.
result
.row[0]
.name = “John”
.surname = “Smith”
.row[1]
.name = “Donald”
.surname = “Duck”
8. Update the table
Update a table it is easy, use update
operation instead of query.
q = “insert into people (name,surname)
values (:name,:surname)”;
q.name = “Homer”;
q.surname = “Simpsons”;
update@Database( q )( result )