麻烦帮忙看看哪里有错误啊~~万分感谢啊~
数据库:
create table test1
(
    id char(10),
    pic image,
);
插入图片代码如下:
第一个页面,inputimage.jsp:
<body>
<form method="post" action="testimage.jsp">
图片:<input type="file" name="image"><br>
<input type="submit">
</form>
</body>
第二个页面,testimage.jsp:
<body>
<%
request.setCharacterEncoding("gb2312"); 
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
connection con=DriverManager.getConnection("jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=student","sa","123");
Statement stmt = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
String filename=request.getParameter("image");
FileInputStream str=new FileInputStream(filename);
String sql = "insert into test1 (id,pic) values(?,?)";
String id = "123"
PreparedStatement pstmt = con.getPreparedStatement(sql); 
pstmt.setString(1,id);
pstmt.setBinaryStream(2,str,str.available());
pstmt.execute();
out.println("Success!");
%>
</body>

解决方案 »

  1.   

    String filename=request.getParameter("image");
    FileInputStream str=new FileInputStream(filename);
    你没有获得 filename 的文件 你request.getParameter("image"); 只是一个字符串 
    你拿他构造流就会失败 因为文件不在你的服务端
     
      

  2.   

    这样啊。。好吧。。麻烦哪位能给我个上传的代码么?
    就是把文件上传到服务器硬盘某个文件夹,然后存路径的代码
    如果方便能把图片读取到网页上的代码贴出来也可以。。万分感谢啦~~
    正在学习jsp中。很多不懂的地方~谢谢啦~
      

  3.   

    上传,那就看你用的什么jar包!