fjenett / sql-library-processing

SQLibrary – a SQL database library for Processing incl. MySQL, SQLite and PostgreSQL
http://fjenett.github.com/sql-library-processing/
37 stars 24 forks source link

How tu use resultSet with postgresql #9

Closed nickbloomzz closed 11 years ago

nickbloomzz commented 11 years ago

Hello,

I wish to populate an array with the query result, and the normal way is with resultSet rs = pgsql.query(query); however I get the message 'cannot convert from void to resultset' even when importing additional libraries. import de.bezier.data.sql.*; import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement;
String user = "postgres"; String pass = "a"; String database = "wordnet30"; ArrayList <String[]> result = new ArrayList<String[]>();

PostgreSQL pgsql; pgsql = new PostgreSQL( this, "localhost:5432", "wordnet30", "postgres", "a" ); if ( pgsql.connect() ) { //Statement st = conn.createStatement(); ResultSet rs = pgsql.query("SELECT * FROM ra"); int columnCount = rs.getMetaData().getColumnCount(); while(pgsql.next()) { String[] row = new String[columnCount]; for (int i = 0; i < columnCount; i++) { row[i] = rs.getString(i+1); } result.add(row);

    }
}
else
{
}
Print(result);

Is there a way around this? Is it feasible to use the JDBC directly in Processing, and avoiding 'public static void main' ? Best regards, Nicholas Bloom

fjenett commented 11 years ago

You are mixing plain JDBC code with my library which is not what it was made for. Use either or, and yes you can use pure JDBC in Processing.

See included examples for how to iterate over a result set.

nickbloomzz commented 11 years ago

Hello, I'm not sure what you mean but the postgresql example certainly does not have anything like result set, and I cannot see 'Result set' anywhere in your code, neither PreparedStatement or CallableStatement.

nickbloomzz commented 11 years ago

And as for using JDBC in Processing, I wish I can, because of all the documented methods, however I can't find an example of how to import JDBC into Processing anywhere on the internet.

fjenett commented 11 years ago

There is no ResultSet because that is not part of my library but what the examples show you is how to iterate results. Please take the time to study those:

https://github.com/fjenett/sql-library-processing/blob/master/examples/PostgreSQL_example1/PostgreSQL_example1.pde