Sql 将文件插入Postgres数据库

Sql 将文件插入Postgres数据库,sql,database,oracle,postgresql,postgresql-9.1,Sql,Database,Oracle,Postgresql,Postgresql 9.1,我正在执行从oracle数据库到postgres 9.0数据库的数据迁移。所有字段都已成功传输,除非我尝试将文件的一列(oracle中的Blob对象)移动到postgres(postgres中的bytea)。这是我得到的例外 org.postgresql.util.PSQLException: ERROR: syntax error at or near "",#\\034\\034(7),01444\\037\'9=82<.342\\377\\333\\000C\\001\\011\\0

我正在执行从oracle数据库到postgres 9.0数据库的数据迁移。所有字段都已成功传输,除非我尝试将文件的一列(oracle中的Blob对象)移动到postgres(postgres中的bytea)。这是我得到的例外

org.postgresql.util.PSQLException: ERROR: syntax error at or near "",#\\034\\034(7),01444\\037\'9=82<.342\\377\\333\\000C\\001\\011\\011\\011\\014\\013\\014\\030\\015\\015\\0302!\\034!22222222222222222222222222222222222222222222222222\\377\\300\\000\\021\\010\\000D\\0004\\003\\001""

请告诉我您是否曾经在postgres 9.0中存储过文件,只是为了好玩,我刚刚创建了一个表(在postgres 9.2中)

并已成功将文件上载到它(使用驱动程序8.3和9.3):


请检查您的驱动程序。

+1要从Oracle迁移到PostgreSql,我已经在Postgres 8.3中试过了,它在哪里工作……请检查您正在使用的Postgres版本。!!我使用了9.2,驱动程序版本为8.3和9.3。请在问题中指定您的版本是的,它起作用了。事实上,我使用的Postgres驱动程序没有指定它的版本,所以我认为它是唯一可用的驱动程序,但在搜索时,我发现有许多更新的驱动程序可用,所以我使用了postgresql-9.3-1100.jdbc3驱动程序,它起作用了。谢谢Oleg Mikhev
Class.forName("org.postgresql.Driver");
        destDatabaseconnection = DriverManager.getConnection(
                rb.getString("DESTINATION_DATABASE_CONNECTION_URL"),
                rb.getString("DESTINATION_DATABASE_CONNECTION_USERNAME"),
                rb.getString("DESTINATION_DATABASE_CONNECTION_PASSWORD"));

        File file = new File("d://img//10090.gif");
        System.out.println(file.isFile());
        FileInputStream fis = new FileInputStream(file);
        prepstmt = destDatabaseconnection
                .prepareStatement("insert into entps.emp_photos(emp_number,emp_photo) values (?,?)");
        prepstmt.setInt(1, 1);

        prepstmt.setBinaryStream(2, fis, (int) file.length());
        int check = prepstmt.executeUpdate();
        System.out.println(check);
CREATE TABLE test
(
  id integer NOT NULL,
  file bytea,
  CONSTRAINT id PRIMARY KEY (id)
)
public static void main(String[] args) throws Exception {
    Class.forName("org.postgresql.Driver");
    Connection conn = DriverManager.getConnection("jdbc:postgresql:test", "postgres", "");
    File file = new File("/tmp/q");
    FileInputStream fis = new FileInputStream(file);
    PreparedStatement pstmt = conn
            .prepareStatement("insert into test(id,file) values (?,?)");
    pstmt.setInt(1, 1);
    pstmt.setBinaryStream(2, fis, (int) file.length());
    int check = pstmt.executeUpdate();
    System.out.println(check);
}