Subject | Re: [Firebird-Java] Insert pdf into firebird database using java |
---|---|
Author | Roman Rokytskyy |
Post date | 2010-04-06T12:52:40Z |
> I am wondering how to insert a pdf file into a table in a firebirdAssuming that you have database "test" set up and a table has two columns:
> database? I am using Java
>
> Anyone got an example I can use?
CREATE TABLE TEST_PDF(
ID INTEGER NOT NULL PRIMARY KEY,
PDF_CONTENT BLOB
);
then your Java code would look like this:
Connection c = DriverManager.openConnection(
"jdbc:firebirdsql:localhost/3050:test",
"SYSDBA",
"masterkey");
try {
PreparedStatement stmt = c.prepareStatement(
"INSERT INTO test_pdf VALUES(?, ?)");
try {
stmt.setInteger(1, <someId>);
stmt.setInputStream(2,
new FileInputStream("c:/my.pdf"));
stmt.executeUpdate();
} finally {
stmt.close();
}
} finally {
c.close();
}
Roman