Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>SQLite supports BLOB datatype. <a href="http://www.zentus.com/sqlitejdbc/" rel="nofollow">Sqlitejdbc driver</a> does not support the ResultSet#getBlob() method but BLOBs are supported. Just use ResultSet#getBytes() method. Here is the sample code (I did not put proper exception handling in this code to make it simple):</p> <pre><code>package test; import java.sql.Connection; import java.sql.DriverManager; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; import java.util.Arrays; public class SQLiteTest { public static void main(String[] args) throws SQLException, ClassNotFoundException { Class.forName("org.sqlite.JDBC"); Connection connection = DriverManager .getConnection("jdbc:sqlite:test.db"); Statement statement = connection.createStatement(); createTable(statement); insertBlob(connection); byte[] bytes = query(statement); System.out.println(Arrays.toString(bytes)); statement.close(); connection.close(); } private static void createTable(Statement statement) throws SQLException { statement.execute("CREATE TABLE test (data BLOB)"); } private static void insertBlob(Connection connection) throws SQLException { PreparedStatement pStatement = connection .prepareStatement("INSERT INTO test VALUES (?)"); pStatement.setBytes(1, new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }); pStatement.execute(); pStatement.close(); } private static byte[] query(Statement statement) throws SQLException { ResultSet rs = statement.executeQuery("SELECT data FROM test"); byte[] bytes = rs.getBytes(1); return bytes; } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload