import java.sql.*;
import java.util.Scanner;

// Most useful for reading material from a database
// On the command line: java -cp .:sqlitejdbc-v056.jar Read
// Make sure that sqlitejdbc-v056.jar is in the proper directory
public class Read {
    public static void main(String[] args) throws ClassNotFoundException, SQLException {
        Class.forName("org.sqlite.JDBC");
        Connection con = DriverManager.getConnection("jdbc:sqlite:testdb");
        Statement stat = con.createStatement();

        boolean done = false;
        Scanner input = new Scanner(System.in);
        while (!done) {
            System.out.print("Enter command: ");
            String cmd = input.nextLine();
            if (cmd.equals("quit")) {
                done = true;
            } else {
                System.out.print("Enter # of columns expected: ");
                int columns = input.nextInt();
                input.nextLine();
                if (stat.execute(cmd)) {
                    ResultSet results = stat.getResultSet();
                    while (results.next()) {
                        for (int c = 1; c <= columns; ++c) {
                            System.out.print(results.getString(c) + "\t");
                        }
                        System.out.println();
                    } 
                }
            }
        }
    }
}

