Writing Binary

From: buki(at)gmx(dot)net (Andreas Buer)
To: pgsql-jdbc(at)postgresql(dot)org
Subject: Writing Binary
Date: 2003-09-03 10:00:26
Message-ID: eae9b1b2.0309030200.2f8953f1@posting.google.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-jdbc

Hi,

I've tried the example explained in the postgresql 7.1 doc.
But somehow it won't work. Instead of a gif I try to store a pdf.

openDB();
// All LargeObject API calls must be within a transaction
db.setAutoCommit(false);

File file = new File("c:/test/d.pdf");
FileInputStream fis = new FileInputStream(file);

PreparedStatement ps =
db.prepareStatement("INSERT INTO blob_test VALUES (?, ?)");

ps.setString(1, file.getName());

// cast because long won't work
ps.setBinaryStream(2, fis, (int)file.length());
ps.executeUpdate();

ps.close();
fis.close();

I get the following output:
16\020h[2>\3345\3209u\316\360#\367<\3.............(seems to be the pdf)
at org.postgresql.core.QueryExecutor.execute(QueryExecutor.java:94)
at org.postgresql.Connection.ExecSQL(Connection.java:398)
at org.postgresql.jdbc2.Statement.execute(Statement.java:130)
at org.postgresql.jdbc2.Statement.executeUpdate(Statement.java:73)
at org.postgresql.jdbc2.PreparedStatement.executeUpdate(PreparedStatement.java:113)
at Blob.main(Blob.java:26)

I'm using PostGreSql 7.1.3, ODBC Driver Version
7.2.4 and j2sdk1.4.1

Best regards

Andi

Browse pgsql-jdbc by date

  From Date Subject
Next Message dipak pal 2003-09-03 10:26:21 A question?
Previous Message Joseph Shraibman 2003-09-02 22:51:27 Re: Why is JDBC so slow?