SQLite & Arraylist
in
Contributed Library Questions
•
1 year ago
Hello there.
In this sketch I take information from an SQLite database. It spits out three basic information User ID (from_dispname), Time (timestamp), and Message (body_xml). However, if there are two or more entries the program spits them all together, and I can't understand how to separate the messages.
I want to format the results to have this structure:
UserID1 + Time1 + Message1 >>> Pass it to Arraylist location0
UserID2 + Time2 + Message2 >>> Pass it to Arraylist location1
Many thanks!
- import de.bezier.data.sql.*;
- String users, messages;
- PFont fontA;
- SQLite db;
- void setup() {
- size( 450, 450 );
- fontA = loadFont("ArialMT-24.vlw");
- db = new SQLite( this, "test.db" ); // open database file
- if ( db.connect() ) {
- // list table names
- db.query( "SELECT * FROM Messages ORDER BY timestamp" );
- while (db.next ()) {
- users = db.getString("from_dispname");
- println(users);
- long timeStamp = Integer.parseInt(db.getString("timestamp")); //Parse string to int
- Date date = new Date(timeStamp*1000);
- println(date);
- messages = db.getString("body_xml");
- println(messages);
- }
- }
- }
1