Using JavaDB from Processing
JDBC is the java api for connecting to sql databases. Since java6, javadb - a small, simple, javabased database-engine is delivered with java. This is a small example of how to access a database with javaDB from a processing-sketch.
First you need to download the driver from the javadb download site select the "All Plattforms" package and extract derby.jar from the zip file.
Add this jar file to your processing-sketch using the "Add File..."-Item form the "Sketch"-Menu.
The following sketch creates a small database containing one table in the setup method (the "drop table ..." statement deletes the table if it already exists. If you want to pregenerate your database or keep it, remove this line.)
In the draw method the foo table gets queried and the "name" column of each row gets printed on the console
import java.sql.Statement;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.DriverManager;
Connection con;
void setup() {
try {
// Tell derby where to put the database files
System.setProperty("derby.system.home", sketchPath("test"));
// tell java which database-driver to use
Class.forName("org.apache.derby.jdbc.EmbeddedDriver");
// create a database named test
con = DriverManager.getConnection("jdbc:derby:test;create=true");
Statement stmt = con.createStatement();
try {
// drop the foo table if it exists
stmt.execute("drop table foo");
} catch (Exception e ) {
}
// create a table named foo and insert two rows
stmt.execute("create table foo ( id integer not null, name varchar(20))");
stmt.executeUpdate("insert into foo values (0, 'foo')");
stmt.executeUpdate("insert into foo values (1, 'bar')");
}
catch (Exception e ) {
e.printStackTrace();
}
noLoop();
}
void draw() {
try {
// select all rows from the foo table
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery("select * from foo");
while( rs.next()) {
// print the content of the "name" column on the console
println(rs.getString("name"));
}
}
catch( Exception e ) {
e.printStackTrace();
}
}
See also:
nested cubes in processing
processing phaseflower
Time Perception
de jong attractor
カード入れ COACHアメリカ正規店より直輸入 並行輸入品の為、? もしあなたが損なわれた力が使ったよりずっと容易なオプションになることを望むなら、商品情報? 少々の型崩れ、ファスナーポケット1、ファスナーポケット外側:!