Re: Large Objects

From: "Nils O(dot) =?iso-8859-1?q?Sel=E5sdal?=" <noselasd(at)frisurf(dot)no>
To: daniel(dot)fisher(at)vt(dot)edu, Daniel Fisher <dfisher(at)vt(dot)edu>, pgsql-jdbc(at)postgresql(dot)org
Subject: Re: Large Objects
Date: 2001-07-27 19:44:03
Message-ID: 01072720440300.28877@space.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-jdbc

On Friday 27 July 2001 16:59, Daniel Fisher wrote:
> I'm am attempting to make one of my Java servlets work with both MySQL &
> Postgres. I'm having some trouble inserting a large object into the
> database. I'm fairly certain that the problem is in my java code because I
> wrote some quick PHP code and it worked fine. The main problem is I'm not
> getting any errors, so I'm kinda stumped. The code appears to run fine, but
> nothing is being inserted into the database. Any help would be appreciated.
>
> ----- Here is my Java source -----
>
> // getConnection gives me a database connection
> // image is a byte[] passed to this function
>
> Connection conn = null;
> PreparedStatement pstmt = null;
>
> try {
>
> conn = getConnection();
> conn.setAutoCommit(false);
> pstmt = conn.prepareStatement("INSERT INTO dfisher (image) VALUES
> (?)"); pstmt.setBytes(1, image);
> pstmt.executeUpdate();
>
> } catch (Exception e) {
> e.printStackTrace();
> }
> finally {
> try { if (pstmt != null) pstmt.close(); } catch (Exception e) {
> e.printStackTrace(); } try { if (conn != null) conn.close(); } catch
> (Exception e) { e.printStackTrace(); } }
> }
if you want to insert Large Objects, you need to use one of the setXXXStream
of the statement, not setBytes.

In response to

Browse pgsql-jdbc by date

  From Date Subject
Next Message Tom Lane 2001-07-29 20:20:14 Re: Large Objects
Previous Message Daniel Fisher 2001-07-27 16:53:49 Re: Large Objects