Cl00e9ment
Cl00e9ment

Reputation: 823

How to manually insert a BLOB into a SQLite database

I want to know how to manually insert a BLOB into my SQLite database. By manually I mean, without using a driver feature that will complete the command like setBytes:

Connection con = DriverManager.getConnection("jdbc:sqlite:database.db");
PreparedStatement stmt = con.prepareStatement("INSERT OR REPLACE INTO test (id, aBlobColumn) VALUES (0, ?)";
stmt.setBytes(1, new byte[] {0x37, 0xe7, 0x9f});
stmt.executeUpdate();

Is it possible to use a command like that:

INSERT OR REPLACE INTO test (id, aBlobColumn) VALUES (0, 37e79f);

or like that:

INSERT OR REPLACE INTO test (id, aBlobColumn) VALUES (0, BLOB(37, e7, 9f));

I don't mind if the command includes base64 data or raw data, I don't want to specifically use hexadecimal.

Upvotes: 0

Views: 3932

Answers (1)

MikeT
MikeT

Reputation: 56943

You can use the following :-

INSERT OR REPLACE INTO test (id, aBlobColumn) VALUES (0, x'37e79f');

However, the value has to be a hex string for it to be a BLOB.

Upvotes: 3

Related Questions