- 论坛徽章:
- 0
|
为什么我只能存取32K的数据,大于32K的数据就不行
建表是这样建的 create table (len int ,data image )
java 代码如下,请指教
<%@ page contentType="text/html; charset=GBK" %>;
<%@ page import="java.sql.*"%>;
<%@ page import="java.lang.*"%>;
<%@ page import="jbsybtest.DBBean"%>;
<%@ page import="jbsybtest.QueryBean"%>;
<%@ page import="java.io.*"%>;
<%
String getType = "";
System.out.println(pageContext.getRequest().getParameter("Type" );
if (pageContext.getRequest().getParameter("Type" !=null)
{
getType = pageContext.getRequest().getParameter("Type" .toString();
if (getType.equals("insert" ){
//file size = 69576 这是我指定的一个文件,为了方便
java.io.File file = new java.io.File("C:\\1.jpg" ;
java.io.FileInputStream fis = new java.io.FileInputStream(file);
System.out.println((int) file.length());
int l = (int) file.length();
Integer intLen = new Integer(l);
ResultSet result = null;
String mSql = null;
PreparedStatement prestmt = null;
DBBean DBLink = new DBBean();
DBLink.openDBConnect();
mSql = "insert into ss (id ,data) values (?,?)";
prestmt = DBLink.getConn().prepareStatement(mSql);
prestmt.setInt(1,1);
prestmt.setBinaryStream (2, fis , l );
DBLink.setAutoCommit(true);
prestmt.executeUpdate();
DBLink.getConn().commit();
} else {
int bytesum=0;
int byteread=0;
ResultSet result=null;
String Sql=null;
PreparedStatement prestmt=null;
DBBean DBLink = new DBBean();
DBLink.openDBConnect();
Sql="select * from dd";
result=DBLink.executeQuery(Sql);
result.next();
java.io.InputStream inStream=result.getBinaryStream("filedata" ;
java.io.FileOutputStream fs=new java.io.FileOutputStream("c:\\xx.jpg" ;
byte[] b = new byte[69576];//file size
int i = 0;
final int unitlen = 16384;
int cbread;
int l = b.length;
for ( i =0;i < l; i+=unitLen){
if (l - i < cbread) {
cbread = inStream.read(b,i,l-i);
}else{
cbread = inStream.read(b,i,unitLen);
}
System.out.println(cbread);
}
fs.write(b);
fs.close();
}}
%>; |
|