SQLite query to Textlist
in
Contributed Library Questions
•
2 years ago
Im a noob to programming anything, so here it goes.... Im attempting to display the last 10 entries of a column in a database table. I need the text to display in a list in the app window. Im getting stuck on the part after Line31, I dont have any idea on how to populate a List with the data queried. After mousePressed the list needs to update to redisplay the latest 10 element query.
The code i have below only shows the last line recieved, where i need to show all lines.
the data base is simple:
Column 1 my KEY, and is a Int, Primary Key that Auto increments with new line added.
Column 2 is ColString, and is text.
Data: with the "|" as the separator between column 1 and 2
1 | DATALINE1
2 | DATALINE2
3 | DATALINE3
4 | DATALINE4
5 | DATALINE5
6 | DATALINE6
- import de.bezier.data.sql.*;
- SQLite db;
- void setup()
- {
- size( 500, 200 );
- db = new SQLite( this, "test.db" ); // open database file
- if ( db.connect() )
- {
- // list table names
- db.query( "SELECT name as \"Name\" FROM SQLITE_MASTER where type=\"table\"" );
- while (db.next())
- {
- println( db.getString("Name"));
- }
- // read all in table "table_one"
- }
- }
- void draw() {
- // text(DbRead, 10,10);
- }
- void mousePressed()
- {
- db.query( "SELECT ColString,KEY FROM SystemRead ORDER BY KEY Desc LIMIT 10" );
- while (db.next())
- {
- String DbRead = (String) db.getString("ColString") ;
- println(DbRead);
- background(0);
- text(DbRead,10,10,500,200);
- }
- }
1