Re: import_bytea function
От | Stephen Davies |
---|---|
Тема | Re: import_bytea function |
Дата | |
Msg-id | 428935bb-71d6-6316-cfac-e28c4eb83f2d@sdc.com.au обсуждение исходный текст |
Ответ на | Re: import_bytea function (Thomas Kellerer <spam_eater@gmx.net>) |
Ответы |
Re: import_bytea function
|
Список | pgsql-general |
On 07/10/16 19:24, Thomas Kellerer wrote: > Stephen Davies schrieb am 07.10.2016 um 10:46: >>> You can store the contents of a file in a bytea using plain JDBC no lo_import() required >>> >>> String sql = "insert into images (id, image_data) values (?,?)"; >>> Connection con = ....; >>> File uploaded = new File("..."); >>> InputStream in = new FileInputStream(uploaded); >>> PreparedStatement pstmt = con.prepareStatement(sql); >>> pstmt.setInt(1, 42); >>> pstmt.setBinaryStream(in, (int)uploaded.length()); >>> pstmt.executeUpdate(); >>> >>> This *only* works with bytea column, not with "large objects". >>> >>> In production code you obviously need to close all resources and handle errors. >>> I left that out for simplicity. > >> That looks reasonable but I need to update rather than insert and my similar >> code with sql="update part set pic=? where id=3" did not work. > > That *will* work (using that myself for updates as well). > > What exactly is your problem? What was the error/exception? > > > > > I tried the prepared statement approach again and this time it worked. No idea what I did wrong last time. However, my display code still does not work. Cheers and thanks, Stephen
В списке pgsql-general по дате отправления: