JSP reads large object CLOB and generates an XML file sample

Source: Internet
Author: User
Tags sql readline stmt
Js|xml| Object | Generate xml| Sample <%@ 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"%>

<meta content= "text/html; charset=gb2312 "http-equiv=" Content-type ">
int i=0;
String Parid = Request.getparameter ("Id_no");
String strSQL;
String content= "";

String xmlFile = "/usr/local/tomcat/webapps/vehicles/test.xml";

Class.forName ("Sun.jdbc.odbc.JdbcOdbcDriver");
String dburl= "JDBC:ORACLE:THIN:@";
Connection con=drivermanager.getconnection (Dburl, "training", "Deep1704sea");
Statement stmt=con.createstatement ();

To read a CLOB or BLOB column using a stream
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);

Write content that is read from the database to a 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);

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.