Iterate a SQL column in Processing

In the following code, I have been able to successfully return the initial value from the column in a database. However, the code returns the same initial value.

How do I get it to iterate?

float database ()
{

    String user     = "";
    String pass     = "";

    String database = "";

    // connect to database on "localhost"
    //
    pgsql = new PostgreSQL( this, "127.0.0.1", database, user, pass );

    // connected?
    if ( pgsql.connect() )
    {
        pgsql.query( "SELECT COUNT(co2) FROM tree" );

        // results found?
        if ( pgsql.next() )
        {

        }

        pgsql.query( "SELECT co2 FROM tree LIMIT 1" );

        while( pgsql.next() )
        //psql.execute();
        {

            return( pgsql.getFloat("co2") );  //it works here
        }
    }
    else
    {
    }
    return(0);
}

void draw(){
      println(database());
      delay(5000);
}
Tagged:

Answers

Sign In or Register to comment.