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

liulang728 316平台 CTO/CIO/技术副总裁/总工程师  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)
...全文
45 点赞 收藏 1
写回复
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
nuboy 2004-10-04
为什么 不试着 只在数据库里存一个 URL 呢
回复
发动态
发帖子
Web 开发
创建于2007-09-28

7.9w+

社区成员

Java Web 开发
申请成为版主
社区公告
暂无公告