What is it?
P5H2 is a library for Processing (P5) the enables the easy use of the ingenious database engine H2.
The beauty of H2 is that is a java base database engine that you can distrubute and start with your script. It also include an administration interface with which you can view and change the contents of your database.
Install
- Download the Library.
- Extract the zip file in your processing library directory. Afterwards the directory [processing]\libraries\p5h2\library should contain the file p5h2.jar and h2.jar. If not adjust the directory structure so that this is the case.
- Restart Processing
Example
import com.algodes.processing.*;
String table = "test";
void setup(){
H2DB h2 = new H2DB(this);
h2.execute("DROP TABLE IF EXISTS " + table + ";");
h2.execute( "CREATE TABLE " + table + " ("+
"id INT NOT NULL IDENTITY,"+
"word VARCHAR( 255 ),"+
"value INTEGER," +
"PRIMARY KEY (id)"+
")"
);
println("insert");
h2.execute( "INSERT INTO " + table + " (id, word, value) VALUES (NULL, 'one', 1)" );
h2.execute( "INSERT INTO " + table + " (id, word, value) VALUES (NULL, 'Two', 2)" );
h2.execute( "INSERT INTO " + table + " (id, word, value) VALUES (NULL, 'three', 3)" );
println("select");
h2.executeQuery( "SELECT * FROM "+table+"" );
println("print results");
while(h2.next()){
println(h2.getInt("value"));
}
}
FAQ
- What is the password for the Admin interface?
- The default "User Name" is "sa" and the password is empty as in "", or nothing at all.
- What is the JDBC URL to access the Admin interface?
- The default is jdbc:h2:test