日期:2014-05-18  浏览次数:20713 次

JSP二进制数据处理
我要把文件以二进制的方式存到数据库中   下面的代码有什么问题啊  
<%@   page   contentType= "text/html;charset=gb2312 "   import= "java.sql.* "%>
<%@   page   import= "java.util.* "%>
<%@   page   import= "java.text.* "%>
<%@   page   import= "java.io.* "%>
<%
Class.forName( "sun.jdbc.odbc.JdbcOdbcDriver ").newInstance();
String   url= "jdbc:odbc:yun ";
String   username= "sa ";
String   password= "123456 ";
Connection   conn=DriverManager.getConnection(url,username,password);

%>
<%

FileInputStream   in=new   FileInputStream( "G:\\Noname1.java ");
String   sql= "insert   into   bindata(id,binfile)   values(4,?) ";
PreparedStatement   pstmt=conn.prepareStatement(sql);
pstmt.setBinaryStream(1,in,in.available());
pstmt.execute();
out.println( "   gongxi! ");
%>

提示:org.apache.jasper.JasperException:   An   exception   occurred   processing   JSP   page   /manage/test2.jsp   at   line   20

17:   PreparedStatement   pstmt=conn.prepareStatement(sql);
18:   //pstmt.setString(1,id);
19:   pstmt.setBinaryStream(1,in,in.available());
20:   pstmt.execute();
21:   out.println( "   gongxi! ");
22:   %>
23:   <html>


大侠指教

------解决方案--------------------
在连接操作和文件操作中加异常处理try{}catch{}
我的异常网推荐解决方案:An exception occurred processing JSP page,http://www.aiyiweb.com/j2se/33144.html