有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

php utf8 oracle clob,用java写/读pdf?

我的任务是使用java webapp更改2个php页面,该应用将上传pdf文件写入clob,并在用户请求下载时读取

我威胁说pdf是字节数组,并且能够正确地读/写它

最大的问题是向后兼容性:php编写的文件不能被我的java webapp读取,反之亦然

提前谢谢你的帮助

注意:不要回答我使用Blob,我知道这是一种简单的方法,但在这种情况下,我们必须假设由于向后兼容性,我们无法在db上创建一个alter表

下面是我将clob读入字节数组的代码:

byte[] result = null;
InputStream            is = null;
ByteArrayOutputStream bos = null;
//...prepare the query to get clob as first column in the resultset
ResultSet rs = stmt.executeQuery();
int len;
int size = 1024;
byte[] buf;
if(rs.next()) {
      is = rs.getBinaryStream(1);
      bos = new ByteArrayOutputStream();
      buf = new byte[size];
      while ((len = is.read(buf, 0, size)) != -1)
         bos.write(buf, 0, len);
      bos.flush();
      bos.close();
      is.close();
      result = bos.toByteArray();
}

rs.close();

下面是将字节数组写入clob的代码:

//...some other sql stuff here...
stmt = conn.prepareStatement("SELECT clob_col FROM my_table WHERE prim_key = ? FOR UPDATE");
stmt.setString(1, param);

ResultSet rs = stmt.executeQuery();
Clob myclob=null;
if(rs.next())
    myclob=rs.getClob(1);

OutputStream writer = myclob.setAsciiStream(1L);
writer.write(allegato);
writer.flush();
writer.close();
stmt = conn.prepareStatement("UPDATE my_table SET clob_col = ? WHERE prim_key = ? ");
stmt.setClob(1, myclob);
stmt.setString(2, param);
stmt.executeUpdate();

甲骨文编码是意大利语。WE8ISO8859P1 php编码是意大利语。UTF8


共 (0) 个答案