首页 | 社区 | 博客 | 招聘 | 文章 | 新闻 | 下载 | 读书 | 代码
亲,您未登录哦! 登录 | 注册

jsp读取大对象CLOB并生成xml文件示例

打印文章

分享到:
<%@ page contentType="text/html; charset=gb2312" %>
<%@ page info="database handler"%>
<%@ page import="java.io.*"%>
<%@ page import="java.net.*"%>
<%@ page import="java.lang.*"%>
<%@ page import="java.util.*"%>
<%@ page import="java.sql.*"%>
<%@ page import="javax.servlet.*"%>
<%@ page import="javax.servlet.http.*"%>
<%@ page import="oracle.sql.CLOB"%>
<%@ page import="oracle.jdbc.driver.OracleResultSet"%>

<html>
<head>
<meta content="text/html; charset=gb2312" http-equiv="content-type">
</head>
<body>
<%
    int i=0;
    String parID = request.getParameter("id_no");
    String strSql;
    String content="";
    
    try{
     String xmlFile = "/usr/local/tomcat/webapps/vehicles/test.xml";
    
        Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
        String dburl="jdbc:oracle:thin:@192.168.15.250:1521:ycdb";
        Connection con=DriverManager.getConnection(dburl,"training","deep1704sea");
        Statement stmt=con.createStatement();
               
        //使用流读取CLOB或BLOB列        
        strSql = "select xmlgen.getxml('select * from account_holder where id_no=''0001''') from dual ";
        ResultSet rs=stmt.executeQuery(strSql);
        if(rs.next()){
         CLOB clob = ((OracleResultSet)rs).getCLOB(1);
         if(clob!=null){
         Reader is = clob.getCharacterStream();
         BufferedReader br = new BufferedReader(is);
         String s = br.readLine();
         while(s!=null){
         //byte[] temp = s.getBytes("iso-8859-1");
         //s = new String(temp);
         content += s;
         s=br.readLine();
         }
         }
        }        
        //out.println(content);
        
        //将从数据库中读出的内容写到文件中
        FileOutputStream fo = new FileOutputStream(xmlFile);
        PrintStream so = new PrintStream(fo);
        so.println(content);
        so.close();
        
        rs.close();
        stmt.close();
        con.close();

      }catch(Exception e){
        out.println(e);
  }
%>
</body>
</html>

本栏文章均来自于互联网,版权归原作者和各发布网站所有,本站收集这些文章仅供学习参考之用。任何人都不能将这些文章用于商业或者其他目的。( Pfan.cn )

编程爱好者论坛

本栏最新文章