上传图片到数据库的问题?

liulang728 2004-10-04 06:08:39
jsp1.jsp页面如下:

<%@ page contentType="text/html; charset=GBK" %>
<html>
<head>
<title>
jsp1
</title>
</head>
<body bgcolor="#ffffff">
<h1>
JBuilder Generated JSP
</h1>
<form method="post" action="jsp4.jsp" enctype="MULTIPART/FORM-DATA" >
uploadImage <input type="file" name="iamge" />
<input type="submit" value="submit" />
</form>
</body>
</html>

jsp4.jsp页面如下:

<%@page contentType="text/html;charset=gb2312"%>
<%@ page language="java"%>
<%@ page import="java.io.*"%>
<%@ page import="java.util.*"%>
<%@ page import="javax.servlet.*"%>
<%@ page import="javax.servlet.http.*"%>
<%@ page import="java.lang.*"%>
<%@ page import="java.sql.*"%>
<html>
<head>
<title>
jsp4
</title>
</head>
<body bgcolor="#ffffff">
<%
String fname=request.getParameter("image");
fname=new String(fname.trim().getBytes("ISO8859_1"), "GBK");
String url=new String();
url="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=test";
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
Connection con=DriverManager.getConnection(url,"sa","mukeliang");
con.setCatalog( "mybase");
String sqlin="insert into picture(picname) values (?)";
File file = new File(fname);
long l1=file.length();
int l2=(int)l1;
try
{
FileInputStream fis = new FileInputStream(file);
PreparedStatement ps = con.prepareStatement(sqlin);

ps.setBinaryStream(1,fis,l2);
ps.executeUpdate();
ps.close();
fis.close();
}
catch(SQLException e) {System.out.println(e); }
%>
</body>
</html>

错误如下:
java.lang.NullPointerException
at org.apache.jsp.jsp4$jsp._jspService(jsp4$jsp.java:100)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:107)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at org.apache.jasper.servlet.JspServlet$JspServletWrapper.service(JspServlet.java:201)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:381)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:473)
...全文
70 1 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
nuboy 2004-10-04
  • 打赏
  • 举报
回复
为什么 不试着 只在数据库里存一个 URL 呢

81,122

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧