主题:向数据库中输入信息显示错误
向数据库中输入信息显示错误
<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" errorPage="" %>
<%@ include file="incoming/conndb.jsp"%>
<%
String username,title,time,content,username1,title1,time1,content1;
username1=request.getParameter("username");
username=(new String(username1.getBytes("iso-8859-1"),"gb2312"));
title1=request.getParameter("title");
title=(new String(title1.getBytes("iso-8859-1"),"gb2312"));
time1=request.getParameter("time");
time=(new String(time1.getBytes("iso-8859-1"),"gb2312"));
content1=request.getParameter("content");
content=(new String(content1.getBytes("iso-8859-1"),"gb2312"));
if(username.length()!=0&&content.length()!=0){
try{
Statement stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
String sql;
sql="insert into bookinfo (USERNAME,TITLE,CONTENT,TIME) values ('"+username+"','"+title+"','"+content+"','"+time+"')";
stmt.executeUpdate(sql);
stmt.close();
conn.close();
out.print("<script language='javascript'>alert('留言成功');window.location.href='index.jsp';</script>");
}catch(Exception e){
out.print("信息错误!");
}
}
else{
out.print("<center>用户名为空或没有留言内容"+"<br><a href=javascript:history.go(-1)>返回</a></center>");
}
%>
以上代码在编译过程中报错:
type Exception report
message
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
org.apache.jasper.JasperException
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:372)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
root cause
[b][b]java.lang.NullPointerException[/b][/b]
org.apache.jsp.chartbook.add1_jsp._jspService(add1_jsp.java:62)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:94)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:324)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
Bookinfo的表结构为:
ID 自动编号
USERNAME 文本
TITLE 文本
CONTENT 文本
TIME 文本
是否我的sql语句有误?
<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" errorPage="" %>
<%@ include file="incoming/conndb.jsp"%>
<%
String username,title,time,content,username1,title1,time1,content1;
username1=request.getParameter("username");
username=(new String(username1.getBytes("iso-8859-1"),"gb2312"));
title1=request.getParameter("title");
title=(new String(title1.getBytes("iso-8859-1"),"gb2312"));
time1=request.getParameter("time");
time=(new String(time1.getBytes("iso-8859-1"),"gb2312"));
content1=request.getParameter("content");
content=(new String(content1.getBytes("iso-8859-1"),"gb2312"));
if(username.length()!=0&&content.length()!=0){
try{
Statement stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
String sql;
sql="insert into bookinfo (USERNAME,TITLE,CONTENT,TIME) values ('"+username+"','"+title+"','"+content+"','"+time+"')";
stmt.executeUpdate(sql);
stmt.close();
conn.close();
out.print("<script language='javascript'>alert('留言成功');window.location.href='index.jsp';</script>");
}catch(Exception e){
out.print("信息错误!");
}
}
else{
out.print("<center>用户名为空或没有留言内容"+"<br><a href=javascript:history.go(-1)>返回</a></center>");
}
%>
以上代码在编译过程中报错:
type Exception report
message
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
org.apache.jasper.JasperException
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:372)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
root cause
[b][b]java.lang.NullPointerException[/b][/b]
org.apache.jsp.chartbook.add1_jsp._jspService(add1_jsp.java:62)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:94)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:324)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
Bookinfo的表结构为:
ID 自动编号
USERNAME 文本
TITLE 文本
CONTENT 文本
TIME 文本
是否我的sql语句有误?