首页 行业资讯 宠物日常 宠物养护 宠物健康 宠物故事

...库中有一个clob类型,怎样在查询以后转换为String类型?

发布网友 发布时间:2022-04-26 23:47

我来回答

2个回答

热心网友 时间:2022-04-13 23:23

首先你的思路就错的,不可能转换成string

把大对象读进byte[]

 

public byte[] function(Connection connection,所需参数) throws EMPException{
  
  PreparedStatement ps = null;
  ResultSet rs = null;
  byte[] data = null;
  try {
   .....省略
   while (rs.next()) {
    oracle.sql.CLOB  clob= (oracle.sql.CLOB) rs.getClob("大对象的字段名");
    InputStream inStream =clob.getBinaryStream();
    long nLen = clob.length();
                int nSize = (int) nLen;
                data = new byte[nSize];
                inStream.read(data);
                inStream.close();
                connection.commit();

   }
  } catch (SQLException e) {
   EMPLog.log(this.getClass().getName(), EMPLog.INFO, 0, e.toString());
  } catch (IOException e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
  } finally {
   try {
    if (rs != null) {
     rs.close();
     rs = null;
    }
    if (ps != null) {
     ps.close();
     ps = null;
    }
   } catch (SQLException e) {
    EMPLog.log(this.getClass().getName(), EMPLog.INFO, 0, e
      .toString());
   }
  }
  return data;
 }

2.直接在页面上将对象读到页面上

<form action="">
<%
    
    response.setContentType("image/jpg");
    response.setHeader("Content-Transfer-Encoding","base");
    ServletOutputStream toClient = response.getOutputStream();
            out.clear();
            out = pageContext.pushBody();
            ByteArrayInputStream in = new ByteArrayInputStream(data); 
            int len;
            byte[] buf = new byte[1024];
            while ((len = in.read(buf, 0, 1024)) != -1) {
             toClient.write(buf, 0, len);
            }
            toClient.flush();
            toClient.close();
        %>
        </form>

热心网友 时间:2022-04-14 00:41

默认Clob是会转成byte[] ,你可以在用的时候转成String

声明声明:本网页内容为用户发布,旨在传播知识,不代表本网认同其观点,若有侵权等问题请及时与本网联系,我们将在第一时间删除处理。E-MAIL:11247931@qq.com