ResultSet

73 views
Skip to first unread message

Sérgio Henrique

unread,
Jan 4, 2013, 6:40:46 AM1/4/13
to sqlit...@googlegroups.com
Is there a way or function that returns a similar ResultSet object? Or maybe an Array.
User have to make the loop to make this?

[code]
    public static ResultSet select(String column, String tableName, String whereSintax) {
        ResultSet rs;
        if (!isActive()) {
            DataBase.createConnection();
        }
        if (isActive()) {
            String command = "SELECT " + column + " FROM " + tableName + " WHERE ";
            command += whereSintax;
            System.out.println("_[>>] Select process...");
            System.out.println(command);
            try {
                
                //rs = stmt.executeQuery(command);  // -> OLD WAY
                
                conn.prepare(command); // with sqlite4java
                
                // ???????
               
            } catch (SQLiteException ex) {
                Logger.getLogger(DataBase.class.getName()).log(Level.SEVERE, null, ex);              
                return null;
            }
            System.out.println("_[OK] done!.");
        } else {
            System.err.println("_[ERRO] Database is missing;.");
            return null;
        }
        return rs;
    }
[/code]

In my studies I found the following:

    SQLiteConnection db = new SQLiteConnection(new File("/tmp/database"));
    db
.open(true);
   
...
   
SQLiteStatement st = db.prepare("SELECT order_id FROM orders WHERE quantity >= ?");
   
try {
      st
.bind(1, minimumQuantity);
     
while (st.step()) {
        orders
.add(st.columnLong(0));
     
}
   
} finally {
      st
.dispose();
   
}
   
...
    db
.dispose();

Then SQLiteStatement maybe considered a ResultSet?


Igor Sereda

unread,
Jan 8, 2013, 1:27:58 PM1/8/13
to sqlit...@googlegroups.com
Sérgio,

Yes, SQLiteStatement may be considered a Statement and ResultSet at the same time. Please note that sqlite4java is not a replacement for JDBC and does not use the same abstractions. If you'd like to deal with a ResultSet-like class, you can write it yourself as a wrapper for SQLiteStatement.

Hope this helps!
Igor
Reply all
Reply to author
Forward
0 new messages