使用java保存图片数据到oracle中的blob字段. (100分)

  • 主题发起人 主题发起人 yps
  • 开始时间 开始时间
Y

yps

Unregistered / Unconfirmed
GUEST, unregistred user!
使用代码如下:
File file=new File("f://map.gif");
out.println(file.length());
java.io.FileInputStream fileint=new FileInputStream(file);
PreparedStatement st1=conn.prepareStatement("update pmanage_employ set photo_bin=?");
st1.setBinaryStream(1,fileint,2000);
st1.executeUpdate();
fileint.close();
以上程序可以正常运行。
但我把2000修改为2002时就会出现以下错误:
500 Servlet Exception
java.sql.SQLException:违反协议
at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:168)
at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:210)
at oracle.jdbc.dbaccess.DBError.check_error(DBError.java:857)
at oracle.jdbc.ttc7.Oclose.receive(Oclose.java:130)
at oracle.jdbc.ttc7.TTC7Protocol.close(TTC7Protocol.java:533)
at oracle.jdbc.driver.OracleStatement.close(OracleStatement.java:595)
at oracle.jdbc.driver.OraclePreparedStatement.privateClose(OraclePreparedStatement.java:290)
at oracle.jdbc.driver.OraclePreparedStatement.close(OraclePreparedStatement.java:235)
at oracle.jdbc.driver.OracleConnection.close_statements(OracleConnection.java:1596)
at oracle.jdbc.driver.OracleConnection.close(OracleConnection.java:899)
at _employc__jsp._jspService(E:/java/jbproject/rongji_eis/pmanage_web/employc.jsp:108)
at com.caucho.jsp.JavaPage.service(JavaPage.java:87)
at com.caucho.jsp.JavaPage.subservice(JavaPage.java:81)
at com.caucho.jsp.Page.service(Page.java:474)
at com.caucho.server.http.FilterChainPage.doFilter(FilterChainPage.java:166)
at com.caucho.server.http.Invocation.service(Invocation.java:277)
at com.caucho.server.http.CacheInvocation.service(CacheInvocation.java:129)
at com.caucho.server.http.HttpRequest.handleRequest(HttpRequest.java:216)
at com.caucho.server.http.HttpRequest.handleConnection(HttpRequest.java:158)
at com.caucho.server.TcpConnection.run(TcpConnection.java:140)
at java.lang.Thread.run(Thread.java:484)

--------------------------------------------------------------------------------
Resin 2.0.2 (built Mon Aug 27 16:52:49 PDT 2001)
难道流量有限制吗?
 
public static void setLargeTextField(PreparedStatement pstmt, int parameterIndex, String value)
throws SQLException
{
Reader bodyReader = null;
try
{
bodyReader = new StringReader(value);
pstmt.setCharacterStream(parameterIndex, bodyReader, value.length());
}
catch(Exception e)
{
e.printStackTrace();
throw new SQLException("Failed to set text field.");
}
}
}
取:
public static String getLargeTextField(ResultSet rs, int columnIndex)
throws SQLException
{
Reader bodyReader = null;
String value = null;
try
{
bodyReader = rs.getCharacterStream(columnIndex);
if(bodyReader == null)
{
String s = null;
return s;
}
char buf[] = new char[256];
StringWriter out = new StringWriter(256);
int i;
while((i = bodyReader.read(buf)) >= 0)
out.write(buf, 0, i);
value = out.toString();
out.close();
}
catch(Exception e)
{
e.printStackTrace();
throw new SQLException("Failed to load text field");
}
finally
{
try
{
bodyReader.close();
}
catch(Exception exception1) { }
}
return value;
}
}
和服务器无关
 
后退
顶部