Water 5-Getting Started and Examples-Level 1 Examples
Database Example

See also: ice

This example demonstrates using the MySql database from Water. We use Water's 'low level' database interface, SQL, for creating a database, a table and a couple of rows. Then we perform queries on the data.

To run the below examples in Steam XML IDE v5
<class customer name=req age=req/>
<set DBC = <resource "jdbc:mysql://localhost/"/> />
null
If you have given your db a username and password, you must use them when creating the resource like so: (probably unnecessary)
<set DBC = <resource."jdbc:mysql"  a_uri="jdbc:mysql://localhost:3306/" 
                                   username="root" 
                                   password="password"/>/>
null
DBC.<execute source="SHOW DATABASES"/>
DBC.<execute source="CREATE DATABASE foo1"/>
<set db1 = <resource "jdbc:mysql://localhost/foo1"/> />
null
db1.<execute source="SHOW TABLES"/>
db1.<execute source="CREATE TABLE customer (name varchar(255), age varchar(255))"/>
db1.<execute source="SHOW TABLES"/>
db1.<execute source='INSERT INTO customer VALUES ("Mike","77")'/>
db1.<execute source='INSERT INTO customer VALUES ("Christopher","88")'/>
db1.<execute source="SELECT * from customer"/>
<set query1=db1.<execute maker=customer source="SELECT * from customer"/> />
null
Example: number of rows found
query1.<length/>2
Example: first row
query1.0
<customer name="Mike" age="77" do_not_run=true/>
Example: first row, value of 'name' column
query1.0.name"Mike"
Example: convert age from a string to an integer so that you can use it in math operations.
integer.<from query1.0.age/>.<plus 1/>
78