Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Please forgive me for savagely plagiarizing my previous answer to <a href="https://stackoverflow.com/questions/3106548/blob-vs-varchar-for-storing-arrays-in-a-mysql-table/3107250#3107250">BLOB vs. VARCHAR for storing arrays in a MySQL table</a>. The other answers over there are also very pertinent.</p> <p>I think Con's approach is probably better than using java serialization since java's builtin serialization will need additional bytes, and non-java applications will have a harder time dealing with the data.</p> <pre><code>public static void storeInDB(ArrayList&lt;Long&gt; longs) throws IOException, SQLException { ByteArrayOutputStream bout = new ByteArrayOutputStream(); DataOutputStream dout = new DataOutputStream(bout); for (long l : longs) { dout.writeLong(l); } dout.close(); byte[] asBytes = bout.toByteArray(); PreparedStatement stmt = null; // however you get this... stmt.setBytes(1, asBytes); stmt.executeUpdate(); stmt.close(); } public static ArrayList&lt;Long&gt; readFromDB() throws IOException, SQLException { ArrayList&lt;Long&gt; longs = new ArrayList&lt;Long&gt;(); ResultSet rs = null; // however you get this... while (rs.next()) { byte[] asBytes = rs.getBytes("myLongs"); ByteArrayInputStream bin = new ByteArrayInputStream(asBytes); DataInputStream din = new DataInputStream(bin); for (int i = 0; i &lt; asBytes.length/8; i++) { longs.add(din.readLong()); } return longs; } } </code></pre> <p>Note: If your lists will sometimes contain more than 31 longs (248 bytes), then you'll need to use BLOB. You cannot use BINARY() or VARBINARY() in MySQL. I realize you're asking about SQLite, but in the spirit of completely plagiarizing my previous answer, I will pretend you're asking about MySQL:</p> <pre><code>mysql&gt; CREATE TABLE t (a VARBINARY(2400)) ; ERROR 1074 (42000): Column length too big for column 'a' (max = 255); use BLOB or TEXT instead </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. 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.
    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