Wednesday, March 12, 2008

[prototype05_mysql to processing]





here we have a found code with our MYSQL data plugged in. when it is run it projects a stream of data. the draw portion(or the output) is not quite working.








PROCESSING
import de.bezier.mysql.*;


// created 2005-05-10 by fjenett
// updated 2005-11-16 by fjenett


MySQL msql;
void setup()
{
size( 100, 100 );
// this example assumes that you are running the
// mysql server locally (on "localhost").
//

// replace --username--, --password-- with your mysql-account.
//
//String user = "--username--";
//String pass = "--password--";

// name of the database to use
//
//String database = "--database--";

// name of the table that will be created
//
String table = "test";

// connect to database of server "localhost"
//
//msql = new MySQL( "localhost", database, user, pass, this );
msql = new MySQL( "SQL06.FREEMYSQL.NET", "ecovis", "fbitonti", "housebed202", this );
if ( msql.connect() )
{
// create a table with an id and a word
//
msql.execute( "CREATE TABLE IF NOT EXISTS " + table + " ("+
"id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,"+
"word VARCHAR( 255 )"+
")"
);

// fill the table with some data
//
msql.execute( "INSERT INTO " + table + " (word) VALUES (\"Lorem\")" );
msql.execute( "INSERT INTO " + table + " (word) VALUES (\"ipsum\")" );
msql.execute( "INSERT INTO " + table + " (word) VALUES (\"dolor\")" );

// now read it back out
//
msql.query( "SELECT * FROM " + table );

while (msql.next())
{
String s = msql.getString("word");
int n = msql.getInt("id");
println(s + " " + n);
}

// need to find out how many rows there are in table?
//
msql.query( "SELECT COUNT(*) FROM " + table );
msql.next();
println( "number of rows: " + msql.getInt(1) );
}
else
{
// connection failed !
}
}

void draw()
{
// i know this is not really a visual sketch ...
}

Labels: , ,


Comments: Post a Comment



<< Home

This page is powered by Blogger. Isn't yours?