N
ncyqhhf
Unregistered / Unconfirmed
GUEST, unregistred user!
[]我修改后的代码如下,就是没有把大文本保存到数据库,帮我看看,在下多谢了:
<font face="Arial, Helvetica, sans-serif"><%@ page language="java" %>
<%@ page contentType="text/html;charset=gb2312"%>
<%@ page import="java.sql.*,java.util.*,java.text.*" errorPage="" %>
<%@page import="java.io.*"%>
<%@page import="oracle.sql.*"%>
<%@page import="oracle.jdbc.driver.*"%>
<jsp:useBean id = "dbtool" scope = "session" class = "com.bms.pub.db.tools" />
<%
Connection conn = null;
Statement stmt = null;
String sql;
ResultSet resultSet = null;
%>
<html>
<head>
<title>大文本的保存</title>
<meta http-equiv="Content-Type" content="text/html;
charset=gb2312">
<style type="text/css">
<!--
.style1 {
font-size: x-large;
font-weight: bold;
}
a:link {
color: #D4D0C8;
}
.style2 {font-size: large}
body {
background-color: #FFFFFF;
}
-->
</style>
</head>
<body>
<form name="form1" method="post" action="">
<font size="2"> </font>
<table width="100%" height="20" border="0" cellpadding="0" cellspacing="0">
<tr bgcolor="#CCCCCC">
<input name="find" type="submit" id="find" value="统计(T)">
</font></div></th>
</tr>
</table>
</form>
<div align="center">ORACLE大文本的保存kkkkkkkkk</div>
<% //初始化
conn = dbtool.connectDatabase("ok");
stmt = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
sql = "select * from hhf";
resultSet = stmt.executeQuery(sql);
//保存大文本
Class.forName("oracle.jdbc.OracleDriver").newInstance();
String connStr="jdbcracle:thinlocalhost:1521:hhfora";
String user="maximo";
String password="maximo";
conn = DriverManager.getConnection(connStr,user,password);
conn.setAutoCommit(false);
stmt=conn.createStatement();
conn.setAutoCommit(false);
PreparedStatement pstmt = conn.prepareStatement("insert into hhf(code,blob) values(?,empty_blob())");
pstmt.setString(1,"66666");
pstmt.executeUpdate();
pstmt.close();
pstmt = conn.prepareStatement("select blob from hhf where code= ? for update");
pstmt.setString(1,"66666");
ResultSet rset = pstmt.executeQuery(sql);
String filename = "d://test.doc";
File f = new File(filename);
FileInputStream fin = new FileInputStream(f);
System.out.println("file size = " + fin.available());
byte[] data = new byte[(int)fin.available()];
fin.read(data);
pstmt = conn.prepareStatement("update hhf set blob=? where code='66666'");
ByteArrayInputStream kk = new ByteArrayInputStream(data);
pstmt.setBinaryStream(1, kk,(int)fin.available());
fin.close();
pstmt.executeUpdate();
pstmt.close();
conn.commit();
conn.close();
%>
</body>
</html>
</font>
<font face="Arial, Helvetica, sans-serif"><%@ page language="java" %>
<%@ page contentType="text/html;charset=gb2312"%>
<%@ page import="java.sql.*,java.util.*,java.text.*" errorPage="" %>
<%@page import="java.io.*"%>
<%@page import="oracle.sql.*"%>
<%@page import="oracle.jdbc.driver.*"%>
<jsp:useBean id = "dbtool" scope = "session" class = "com.bms.pub.db.tools" />
<%
Connection conn = null;
Statement stmt = null;
String sql;
ResultSet resultSet = null;
%>
<html>
<head>
<title>大文本的保存</title>
<meta http-equiv="Content-Type" content="text/html;
charset=gb2312">
<style type="text/css">
<!--
.style1 {
font-size: x-large;
font-weight: bold;
}
a:link {
color: #D4D0C8;
}
.style2 {font-size: large}
body {
background-color: #FFFFFF;
}
-->
</style>
</head>
<body>
<form name="form1" method="post" action="">
<font size="2"> </font>
<table width="100%" height="20" border="0" cellpadding="0" cellspacing="0">
<tr bgcolor="#CCCCCC">
<input name="find" type="submit" id="find" value="统计(T)">
</font></div></th>
</tr>
</table>
</form>
<div align="center">ORACLE大文本的保存kkkkkkkkk</div>
<% //初始化
conn = dbtool.connectDatabase("ok");
stmt = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
sql = "select * from hhf";
resultSet = stmt.executeQuery(sql);
//保存大文本
Class.forName("oracle.jdbc.OracleDriver").newInstance();
String connStr="jdbcracle:thinlocalhost:1521:hhfora";
String user="maximo";
String password="maximo";
conn = DriverManager.getConnection(connStr,user,password);
conn.setAutoCommit(false);
stmt=conn.createStatement();
conn.setAutoCommit(false);
PreparedStatement pstmt = conn.prepareStatement("insert into hhf(code,blob) values(?,empty_blob())");
pstmt.setString(1,"66666");
pstmt.executeUpdate();
pstmt.close();
pstmt = conn.prepareStatement("select blob from hhf where code= ? for update");
pstmt.setString(1,"66666");
ResultSet rset = pstmt.executeQuery(sql);
String filename = "d://test.doc";
File f = new File(filename);
FileInputStream fin = new FileInputStream(f);
System.out.println("file size = " + fin.available());
byte[] data = new byte[(int)fin.available()];
fin.read(data);
pstmt = conn.prepareStatement("update hhf set blob=? where code='66666'");
ByteArrayInputStream kk = new ByteArrayInputStream(data);
pstmt.setBinaryStream(1, kk,(int)fin.available());
fin.close();
pstmt.executeUpdate();
pstmt.close();
conn.commit();
conn.close();
%>
</body>
</html>
</font>