I hope I'm not OT, if I am please forgive me!

I'm writing a Java application I use sqlite to save data on disk.

Everything works fine, I used sqlite successfully for months, with any
type of data but bytes.

I need to store and read from my sqlite database BLOB fields.

I created a table "CREATE TABLE DOCUMENTS (id integer primary key,
saveddata blob)"

And I try to query the table with the simple query: "SELECT saveddata
FROM DOCUMENTS WHERE id = ? "

I'm using the jdbc driver: http://www.xerial.org/trac/Xerial/wiki/SQLiteJDBC

I cannot figure out why, when I call the fuction getBytes in my result
set, my application crashes.

The Java driver is simply a wrapper, the application does not throw
any exeption, so I suppose that the problem is in the sqlite layer.

The code is very basic:

FileOutputStream str = new FileOutputStream("Filename.....");
Connection conn = SQLiteConnection.openConnection(fileName);
Statement stat = SQLiteConnection.openStatement(conn);
PreparedStatement prep = SQLiteConnection.openPreparedStatement(conn,
"SELECT saveddata FROM DOCUMENTS WHERE id = ? ");
byte[] by = null;
try {
     prep.setLong(1, id);
     prep.execute();

     ResultSet rs = prep.getResultSet();

     if (rs.next()) {
           byte[] outbyt = rs.getBytes(1);
           try {
                str.write(outbyt);
           } catch (IOException ex)
                Exceptions.printStackTrace(ex);
           }
     }

     rs.close();
     prep.close();
     conn.close();
} catch (SQLException ex) {
     Exceptions.printStackTrace(ex);
}


The execution of the code stops when the rs.getBytes(1); is called.

What can I do?

Fabio
_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to