jsp读取大对象CLOB并生成xml文件示例
程序员文章站
2024-02-23 11:42:04
<%@ page contenttype="text/html; charset=gb2312" %&...
<%@ 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>
上一篇: java线性表排序示例分享