Reputation: 117
I ran into an awkward problem.
I need to insert some values into an SQL table.
For that i use an Insert
clause, like this:
INSERT INTO `USERS`(`ID`, `FILE`, `PROPERTIES`) VALUES ('1', FILE, '{"attributes":{"LANGUAGE":"ENG","AUTHOR":"John"}}')
My problem is the File
value. I don't know how i can insert a File
object in these circumstances. And since i cannot pass the value NULL
, due to program restrictions, how can i do it?
Upvotes: 0
Views: 114
Reputation: 5948
Most persistence libraries won't let you do this directly. (none that I'm aware of)
convert the file into a byte array using IOUtils.toByteArray(InputStream input)
or an equivalent
(if using JDBC) call PreparedStatement.setBytes(byte[] b)
to pass this value to the database
Alternative solution: put the actual file in some known disk location and store only the filename/path in the database.
Upvotes: 1