日期:2014-05-20  浏览次数:20619 次

求 ,sql数据库中操作image 字段的Java代码
求 ,sql数据库中操作image 字段的Java代码

sql 2005 数据库,

求添加,修改, 和 提取一个 image 字段的Java代码 

最好有哪个高手能给些完整具体的代码。。

谢谢了。

------解决方案--------------------
updatetest
用存储过程吧
------解决方案--------------------

Java code

Connection con = ...
        int[] data = ...
        PreparedStatement stmt= con.prepareStatement("insert into t_test(array_field) values(?)");
        stmt.setObject(1, data,java.sql.Types.BINARY);
        stmt.execute();

------解决方案--------------------
正好项目有,就给你一个读取的代码吧.不能完全相同,你自己改一下吧:
Java code

FileOutputStream out = null;
InputStream in = null;
//SQL语句我就不写了,就是select那个字段

try {
if(rs.next()) {
    out = new FileOutputStream("C:\a.jpg");
    in = rs.getBinaryStream("image1");
    byte b[] = new byte[0x7a120];
    for (int i = in.read(b); i != -1;) {
        out.write(b);
      i = in.read(b);
    }
    }
    } catch (Exception e) {
    System.out.println(e);
    }