Jsp reads large object CLOB and generates xml file example

Source: Internet
Author: User
Tags xml file example


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

// Use stream to read CLOB or BLOB Columns
StrSql = "select xmlgen. getxml ('select * from account_holder where id_no = ''000000') from dual ";
ResultSet rs1_stmt.exe cuteQuery (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 );

// Write the content read from the database to the file
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>

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.