Let\'s say I want to avoid using bind variables in JDBC and run SQL using \"ad-hoc\" statements, e.g:
connection.createStatement().executeQuery(\"SELECT ...\
I'd like to add some PostgreSQL specific stuff to Lukas' answer:
The shortest and most easiest solution would be (since PostgreSQL 9.0 at least):
insert into lob_table (data) values( E'\\x0102030405FF' )
without any cast (if the column is already a bytea one) and only one \\x mark right at the beginning. This is the "hex format" documented in the section Binary Data Types.
Regarding the X'01FF' syntax: According to the string constant documentation PostgreSQL does support it - for bit strings. And it seems, that there is no standard conversion from bit to bytea.