JSP向数据库提交时出现错误?为什么啊

standout 2002-04-11 02:29:26
JSP向数据库提交时出现如下错误
JSP文件内容如下:
<html>
<head>
<title>无标题文档</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</head>

<body bgcolor="#CCFFCC" text="#666600" link="#009900" alink="#00FF00" vlink="#006600">
<center>
<table width="800" border="0" cellpadding="0" cellspacing="0">
<tr>
<th width="800" height="51" valign="top">
<table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="800" height="51" valign="top">
<table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="800" height="51" valign="top">
<div align="center"><font size="4"><b><font color="#6633FF">元为留言板--载入史册</font></b></font></div>
<br>
</td>
</tr>
</table>
</td>
</tr>
</table>
</th>
</tr>
<%-- 日期:2002年4月2日--%>

<%@ page contentType="text/html; charset=GB2312" %>
<%@ page import="java.sql.*" %>

<%-- 声明变量,SQL为要操作的SQL语句,cip为记录的客户端IP地址--%>

<%
int n=0;
String SQL=new String();
String cip=new String();

%>

<%--建立数据库连接--%>

<%
String url=new String("jdbc:odbc:leaveword");
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection(url,"sa","");
%>

<%--取出传过来的数据,并进行国标字符的转换--%>
<%
String cid=new String((request.getParameter("txtid")).getBytes("ISO8859-1"),"GB2312");
String cname=new String((request.getParameter("txtname")).getBytes("ISO8859-1"),"GB2312");
String cword=new String((request.getParameter("txtcontent")).getBytes("ISO8859-1"),"GB2312");
String cmail=new String((request.getParameter("txtemail")).getBytes("ISO8859-1"),"GB2312");
String chomepage=new String((request.getParameter("txthomepage")).getBytes("ISO8859-1"),"GB2312");
String cqq=new String((request.getParameter("txtqq")).getBytes("ISO8859-1"),"GB2312");
String csf=new String((request.getParameter("txtsf")).getBytes("ISO8859-1"),"GB2312");
String ctitle=new String((request.getParameter("txttitle")).getBytes("ISO8859-1"),"GB2312");
cip=request.getRemoteAddr();

n=cid.length()*cname.length()*cword.length();
%>
<%--进行插入记录操作,并取出数据库中所有记录,显示出来!--%>
<%
if(n==0)
{
out.println("error");
}
else
{
SQL="insert into leaveword_t(id,content,ip,address,name,email,homepage,qq,title) values('"+cid+"','"+cword+"','"+cip+"','"+csf+"','"+cname+"','"+cmail+"','"+chomepage+"','"+cqq+"','"+ctitle+"')";

Statement stmt=con.createStatement();
stmt.executeUpdate(SQL);
SQL="select * from leaveword_t";
ResultSet rs=stmt.executeQuery(SQL);


while(rs.next())
{
%>

<tr>
<td height="21" valign="top">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr bgcolor="#9999FF">
<td width="7%" height="15">
<div align="center"><font size="2" color="#660066">呢称</font></div>
</td>
<td width="4%" height="15">
<div align="center"><font color="#660066" size="2">IP</font></div>
</td>
<td width="22%" height="15">
<div align="center"><font color="#660066" size="2">来自地</font></div>
</td>
<td width="13%" height="15">
<div align="center"><font color="#660066" size="2">名字</font></div>
</td>
<td width="16%" height="15">
<div align="center"><font color="#660066" size="2">邮件</font></div>
</td>
<td width="18%" height="15">
<div align="center"><font color="#660066" size="2">主页</font></div>
</td>
<td width="20%" height="15">
<div align="center"><font color="#660066" size="2">QQ号码</font></div>
</td>
</tr>
<tr bgcolor="#9966FF">
<th width="7%"><font color="#660066"><% out.print(rs.getString("id")); %></font></th>
<th width="4%"><font color="#660066"><% out.print(rs.getString("ip")); %></font></th>
<th width="22%"><font color="#660066"><% out.print(rs.getString("address")); %></font></th>
<th width="13%"><font color="#660066"><% out.print(rs.getString("name")); %></font></th>
<th width="16%"><font color="#660066"><% out.print(rs.getString("email")); %></font></th>
<th width="18%"><font color="#660066"><% out.print(rs.getString("homepage")); %></font></th>
<th width="20%"><font color="#660066"><% out.print(rs.getString("qq")); %></font></th>
</tr>
</table>
</td>
</tr>
<tr>
<td height="18" valign="top">
<table width="100%" border="0" cellspacing="0" cellpadding="0" bgcolor="#666666">
<tr bgcolor="#CCFFCC">
<td height="14" bgcolor="#9999FF">
<div align="center"><font size="2" color="#660066"><b>标题</b></font></div>
</td>
</tr>
<tr bgcolor="#CCFFCC">
<td height="14" bgcolor="#9966FF"><% out.println(rs.getString("title"));%></td>
</tr>
</table>
</td>
</tr>
<tr>
<td height="17" valign="top">
<div align="left">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td bgcolor="#9999FF">
<div align="center"><font size="2"><b><font color="#660066">内容</font></b></font></div>
</td>
</tr>
<tr>
<td bgcolor="#9966FF"><% out.println(rs.getString("content"));%></td>
</tr>
</table>
</div>
</td>
</tr>

<%
}
out.print("<hr>");
}
%>

<tr>
<td height="18" valign="top">
<div align="right"><font size="2" color="#660066"><a href="index.html">我要留言</a></font></div>
</td>
</tr>
<tr>
<td height="503"></td>
</tr>
</table>
</center>





</body>

</html>


错误如下:
type Exception report

message Internal Server Error

description The server encountered an internal error (Internal Server Error) that prevented it from fulfilling this request.

exception

javax.servlet.ServletException: [Microsoft][ODBC SQL Server Driver]无效的描述符索引
at org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:457)
at org.apache.jsp.addword$jsp._jspService(addword$jsp.java:231)
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:202)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:382)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:474)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:247)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:243)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:201)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
at org.apache.catalina.core.StandardContext.invoke(StandardContext
附加文件:

返回

...全文
42 点赞 收藏 5
写回复
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
littleyy 2002-04-11
是这样的,我也有过类似的问题

你从数据库里面取出的时候,一定要按照设计好的字段顺序,不能前后倒置。
回复
wjfxiao 2002-04-11
你最好先把你的SQL语句在数据库中测一下,现在的报错是因为数据库操作出错。测完SQL语句,确定无误后,再看JSP
回复
scarab 2002-04-11
rs.get方法
取数据的顺序和数据库的字段顺序保持一致
试一下看看
回复
zhjx_10 2002-04-11
字段名字都对吗?
回复
可乐加水 2002-04-11
太长了,你检查一下你的数据库字段的类型和你插入的内容的类型是否匹配!
回复
发动态
发帖子
Web 开发
创建于2007-09-28

7.9w+

社区成员

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