// 2014 Winter MAT 259 Data Visualization // Lab.3 SQL in Processing - connect mySQL into Processing // Works fine with both Processing ver. 1.5.1 & 2. // by Yoon Chung Han // To import SQL Library, please download it here // (http://bezier.de/processing/libs/sql/) // and move the SQLibrary folder into your libraries folder. // (Please follow the detailed instruction from the website) import de.bezier.data.sql.*; MySQL msql; String DL = ","; //the DELIMITER void setup() { // connecting to the SPL database msql = new MySQL( this, "tango.mat.ucsb.edu", "spl2", "mat259", "V1sual1zat1on" ); //host, database, user, password if ( msql.connect() ) { String TheQuery="select date(cout),date(cin),itemtype, timestampdiff(HOUR,cout,cin)/24.0 from inraw where cout between '2011-01-10' and '2011-01-11' order by itemtype;"; println(TheQuery); msql.query( TheQuery); msql.next(); int count = 0; while( msql.next() ){ println( msql.getString(1) + DL + msql.getString(2) + DL + msql.getString(3) + DL + msql.getString(4)); count++; } } else { println(" connection failed !"); } }