Clob type for Oracle Database Operations

Source: Internet
Author: User
Tags html encode
<% @ Page contenttype = "text/html; charset = gb2312" Language = "Java" %>
<% @ Page import = "Java. util. *, java. SQL. *, Oracle. SQL. *, java. Io. *" %>
<! Doctype HTML public "-// W3C // dtd html 4.01 transitional // en"
Http://www.w3.org/TR/html4/loose.dtd>
<HTML>
<Head>
<Meta http-equiv = "Content-Type" content = "text/html; charset = gb2312">
<Title> Oracle operation </title>
<Style type = "text/CSS">
<! --
TD {
Font-family: Arial, Helvetica, sans-serif;
Font-size: 14px;
Color: #000000;
Text-Decoration: none;
}
-->
</Style>
</Head>
<Body>
<%
Java. SQL. Connection conn; // database connection object \ r
Java. Lang. String strcon; // database connection string
Strcon = "JDBC: oracle: thin :@ localhost: 1521: ";
Java. Lang. String strsql; // SQL statement \ r
// Try {

Class. forname ("oracle. JDBC. Driver. oracledriver"). newinstance ();
Conn = java. SQL. drivermanager. getconnection (strcon, "Kevin", "DDD ");
Statement stmt = conn. createstatement ();
Java. SQL. preparedstatement pstmt = NULL;
Boolean defacomcommit = conn. getautocommit ();
Conn. setautocommit (false );
String query;
Query = "select * From tblproduct ";
Pstmt = conn. preparestatement (query );
Resultset rs = pstmt.exe cutequery ();

%>
<Table width = "770" border = "0" align = "center" cellpadding = "0" cellspacing = "1" bgcolor = "# e7e7e7">
<%
String content = "";
String description = "";
While (Rs. Next ()){
Oracle. JDBC. Driver. oracleresultset ors =
(Oracle. JDBC. Driver. oracleresultset) RS;
Clob clobtmp = (clob) ors. getclob (8 );
If (clobtmp = NULL | clobtmp. Length () = 0 ){
// Out. println ("===== clob object is blank ");
Description = "";
} Else {
Description = clobtmp. getsubstring (long) 1, (INT) clobtmp. Length ());
// Out. println ("====== string format" + description );
}
// Clob. empty_lob ();
/* Output in character form */
/* Bufferedreader in = new bufferedreader (clob. getcharacterstream ());
Bufferedwriter out2 = new bufferedwriter (New filewriter ("test.txt "));
Int C;
*/
String STR = "";
If (clobtmp! = NULL ){
Reader is = clobtmp. getcharacterstream ();
Bufferedreader BR = new bufferedreader (is );
STR = Br. Readline ();
}

%>
<Tr bgcolor = "# ffffff">
<TD Height = "19"> <% Out. println (Rs. getstring (1); %> </TD>
<TD> <% Out. println (Rs. getstring (2); %> </TD>
<TD> <% Out. println (Rs. getstring (4); %> </TD>
<TD> <% = STR %> </TD>
<TD> <% = Description %> </TD>
</Tr>
<%
}
%>
</Table>
<%
Rs. Close ();
Stmt. Close ();
Conn. Close ();
/*
}
Catch (exception e ){
Out. println ("error" + E );
}
*/
%>
</Body>
</Html> <% @ page contenttype = "text/html; charset = gb2312" Language = "Java" %>
<% @ Page import = "Java. util. *, java. Lang. *, java. SQL. *, java. Io. *" %>
<% @ Page import = "oracle. SQL. *, webutil. *" %>
<! Doctype HTML public "-// W3C // dtd html 4.01 transitional // en"
Http://www.w3.org/TR/html4/loose.dtd>
<HTML>
<Head>
<Meta http-equiv = "Content-Type" content = "text/html; charset = gb2312">
<Title> Oracle operation </title>
<Style type = "text/CSS">
<! --
TD {
Font-family: Arial, Helvetica, sans-serif;
Font-size: 14px;
Color: #000000;
Text-Decoration: none;
}
-->
</Style>
</Head>
<Body>
<%
Java. SQL. Connection conn; // database connection object \ r
Java. Lang. String strcon; // database connection string
Stringbuffer SBF;
SBF = new stringbuffer ();

Strcon = "JDBC: oracle: thin :@ localhost: 1521: ";
Java. Lang. String strsql, strtmp; // SQL statement \ r
Strtmp = "testestsetse ";
// Try {
Class. forname ("oracle. JDBC. Driver. oracledriver"). newinstance ();
Conn = java. SQL. drivermanager. getconnection (strcon, "Kevin", "DDD ");
Statement stmt = conn. createstatement ();
Java. SQL. preparedstatement pstmt = NULL;
Resultset rs = NULL;
String query = "", description = "";
Conn. setautocommit (false );

File F = NULL;
F = new file ("I: // JSP // exercise // Oracle // humor.txt ");
Fileinputstream Fi = new fileinputstream (f );
Int size = Fi. Available ();
For (INT I = 0; I <size; I ++)
{
// System. Out. Print (char) Fi. Read ());
SBF. append (char) Fi. Read ());
}
Fi. Close ();

Query = "insert into tblproduct (proid, prodetail, productname) values (?, Empty_clob (),?) ";
Pstmt = conn. preparestatement (query );
Pstmt. setint (1, 68 );
Pstmt. setstring (2, "GG ");
Pstmt.exe cuteupdate ();
Pstmt = NULL;
Query = "select prodetail from tblproduct where proid = 68 for update ";
Pstmt = conn. preparestatement (query );
Rs = pstmt.exe cutequery ();

Clob clobtt = NULL;
If (Rs. Next ()){
Oracle. JDBC. Driver. oracleresultset ors = (Oracle. JDBC. Driver. oracleresultset) RS;
Clobtt = (clob) ors. getclob (1 );

}

/* // Write data to the clob object
Bufferedwriter BW = new bufferedwriter (clobtt. getcharacteroutputstream ());
Bufferedreader in = new bufferedreader (New filereader ("I: // JSP // exercise // Oracle // humor.txt "));
Int C;
While (C = in. Read ())! =-1 ){
Bw. Write (C );
}
In. Close ();
Bw. Close ();
*/

Writer wR = clobtt. getcharacteroutputstream ();
String strsbf = new string (SBF. tostring (). getbytes ("iso8859_1"), "gb2312 ");

Wr.write(webutil.html encode (strsbf ));
Wr. Flush ();
Wr. Close ();

Rs. Close ();
Conn. Commit ();
// Out.print(webutil.html encode (SBF. tostring ()));
%>
<Table width = "770" border = "0" align = "center" cellpadding = "0" cellspacing = "0" bgcolor = "# e7e7e7">

<Tr bgcolor = "# ffffff">
<TD Height = "19"> </TD>
<TD> </TD>
<TD> </TD>
<TD> </TD>
<TD> </TD>
</Tr>

</Table>
<%
/*
}
Catch (exception e ){
Out. println ("error" + 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.