<%@ 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; //資料庫連接對象\r
java.lang.String strCon; //資料庫連接字串
strCon ="jdbc:oracle:thin:@localhost:1521:via";
java.lang.String strSQL; //SQL語句\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 defaultCommit = conn.getAutoCommit();
conn.setAutoCommit(false);
String query;
query ="select * from tblproduct ";
pstmt = conn.prepareStatement(query);
ResultSet rs = pstmt.executeQuery();
%>
<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對象為空白 ");
description = "";
}else{
description=clobtmp.getSubString((long)1,(int)clobtmp.length());
//out.println("======字串形式 "+description);
}
//clob.empty_lob();
/* 以字元形式輸出 */
/*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; //資料庫連接對象\r
java.lang.String strCon; //資料庫連接字串
StringBuffer sbf;
sbf= new StringBuffer();
strCon ="jdbc:oracle:thin:@localhost:1521:via";
java.lang.String strSQL,strtmp; //SQL語句\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.executeUpdate();
pstmt = null;
query = "select prodetail from tblproduct where proid = 68 for update";
pstmt = conn.prepareStatement(query);
rs= pstmt.executeQuery();
CLOB clobtt = null;
if(rs.next()){
oracle.jdbc.driver.OracleResultSet ors = (oracle.jdbc.driver.OracleResultSet)rs;
clobtt = (CLOB)ors.getClob(1);
}
/* //向CLOB對象中寫入資料
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.htmlEncode(strSbf));
wr.flush();
wr.close();
rs.close();
conn.commit();
//out.print(WebUtil.htmlEncode(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>