Обсуждение: Large Object

Поиск
Список
Период
Сортировка

Large Object

От
Andreas Bauer
Дата:
Hi,

I don't want to annoy anyone, but I just can't write a large object.
Code:
File file = null;
FileInputStream fis = null;
try{file = new File("c:/testen/test.pdf");
fis = new FileInputStream(file);}catch(Exception e){e.printStackTrace();}
try{
dat.openDB();
dat.db.setAutoCommit(false);
PreparedStatement ps = dat.db.prepareStatement("INSERT INTO blob_test VALUES
(?, ?)");
ps.setString(1, file.getName());
ps.setBinaryStream(2, fis, (int)file.length());
ps.executeUpdate();
System.out.println(ps.toString()); // shows: INSERT INTO blob_test VALUES
('test.pdf, 390368)
ps.close();}catch(Exception e){e.printStackTrace();}
fis.close();

The table looks like this:

CREATE TABLE blob_test (
  name varchar(35),
  pdf oid
);

Some further questions. How can this funny number in the insert-statement
represent a
binary file? Is it right, that the file lying somewhere on the harddisk can
be written with
this setBinaryStream-command into a db lying on a server?

Thanks in advance for any hint.

Andi

--
COMPUTERBILD 15/03: Premium-e-mail-Dienste im Test
--------------------------------------------------
1. GMX TopMail - Platz 1 und Testsieger!
2. GMX ProMail - Platz 2 und Preis-Qualitätssieger!
3. Arcor - 4. web.de - 5. T-Online - 6. freenet.de - 7. daybyday - 8. e-Post


Re: Large Object

От
Paul Thomas
Дата:
On 04/09/2003 10:44 Andreas Bauer wrote:
> Hi,
>
> I don't want to annoy anyone, but I just can't write a large object.
> Code:
> File file = null;
> FileInputStream fis = null;
> try{file = new File("c:/testen/test.pdf");
> fis = new FileInputStream(file);}catch(Exception e){e.printStackTrace();}
> try{
> dat.openDB();
> dat.db.setAutoCommit(false);
> PreparedStatement ps = dat.db.prepareStatement("INSERT INTO blob_test
> VALUES
> (?, ?)");
> ps.setString(1, file.getName());
> ps.setBinaryStream(2, fis, (int)file.length());
> ps.executeUpdate();
> System.out.println(ps.toString()); // shows: INSERT INTO blob_test VALUES
> ('test.pdf, 390368)
> ps.close();}catch(Exception e){e.printStackTrace();}
> fis.close();
>
> The table looks like this:
>
> CREATE TABLE blob_test (
>   name varchar(35),
>   pdf oid
> );

Your table definition is for use withe the Large Object storage mechanism
but your code is for storing binary data in a bytea column.

--
Paul Thomas
+------------------------------+---------------------------------------------+
| Thomas Micro Systems Limited | Software Solutions for the Smaller
Business |
| Computer Consultants         |
http://www.thomas-micro-systems-ltd.co.uk   |
+------------------------------+---------------------------------------------+

Re: Large Object

От
Toby Doig
Дата:
you did commit the transaction aftwards, right?

dat.db.commit();

On Thu, 4 Sep 2003, Andreas Bauer wrote:

> Hi,
>
> I don't want to annoy anyone, but I just can't write a large object.
> Code:
> File file = null;
> FileInputStream fis = null;
> try{file = new File("c:/testen/test.pdf");
> fis = new FileInputStream(file);}catch(Exception e){e.printStackTrace();}
> try{
> dat.openDB();
> dat.db.setAutoCommit(false);
> PreparedStatement ps = dat.db.prepareStatement("INSERT INTO blob_test VALUES
> (?, ?)");
> ps.setString(1, file.getName());
> ps.setBinaryStream(2, fis, (int)file.length());
> ps.executeUpdate();
> System.out.println(ps.toString()); // shows: INSERT INTO blob_test VALUES
> ('test.pdf, 390368)
> ps.close();}catch(Exception e){e.printStackTrace();}
> fis.close();
>
> The table looks like this:
>
> CREATE TABLE blob_test (
>   name varchar(35),
>   pdf oid
> );
>
> Some further questions. How can this funny number in the insert-statement
> represent a
> binary file? Is it right, that the file lying somewhere on the harddisk can
> be written with
> this setBinaryStream-command into a db lying on a server?
>
> Thanks in advance for any hint.
>
> Andi
>
> --
> COMPUTERBILD 15/03: Premium-e-mail-Dienste im Test
> --------------------------------------------------
> 1. GMX TopMail - Platz 1 und Testsieger!
> 2. GMX ProMail - Platz 2 und Preis-Qualitätssieger!
> 3. Arcor - 4. web.de - 5. T-Online - 6. freenet.de - 7. daybyday - 8. e-Post
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 8: explain analyze is your friend
>