溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶(hù)服務(wù)條款》

jsp讀取大對(duì)象CLOB并生成xml文件示例(轉(zhuǎn))

發(fā)布時(shí)間:2020-08-06 21:40:15 來(lái)源:ITPUB博客 閱讀:158 作者:rainytag 欄目:編程語(yǔ)言
<%@ 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"%>






<%
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);

//將從數(shù)據(jù)庫(kù)中讀出的內(nèi)容寫(xiě)到文件中
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);
}
%>


[@more@]
向AI問(wèn)一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI