CSDN首页 空间 新闻 论坛 Blog 下载 读书 网摘 搜索 .NET Java 视频 接项目 求职 在线学习 买书 程序员 通知
不看会后悔的Windows XP之经验谈 简单快捷DIY实用家庭影院
CSDN社区
搜索 收藏 打印 关闭
CSDN社区 >  Java >  Web 开发

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

楼主standout(元为)2002-04-11 14:29:26 在 Java / Web 开发 提问

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  
  附加文件:    
   
  返回      
   
  问题点数:50、回复次数:5Top

1 楼realyfly(^_^)回复于 2002-04-11 14:35:43 得分 10

太长了,你检查一下你的数据库字段的类型和你插入的内容的类型是否匹配!Top

2 楼zhjx_10(色子)回复于 2002-04-11 14:38:51 得分 5

字段名字都对吗?Top

3 楼scarab(没有尾巴的鲨鱼)回复于 2002-04-11 14:44:14 得分 15

rs.get方法  
  取数据的顺序和数据库的字段顺序保持一致  
  试一下看看Top

4 楼wjfxiao(野渡无人舟自横)回复于 2002-04-11 14:45:25 得分 5

你最好先把你的SQL语句在数据库中测一下,现在的报错是因为数据库操作出错。测完SQL语句,确定无误后,再看JSPTop

5 楼littleyy(风笑痴)回复于 2002-04-11 17:39:13 得分 15

是这样的,我也有过类似的问题  
   
  你从数据库里面取出的时候,一定要按照设计好的字段顺序,不能前后倒置。Top

相关问题

  • JSP访问数据库错误。
  • :( jsp连接mysql数据库错误!
  • 数据库同时提交发生错误
  • 我的jsp连接数据库时,出现以下错误呀!
  • 求教JSP访问ACCESS数据库的SQL语句错误
  • JSP嵌套访问数据库出现错误.....
  • JSP如何把文章内容提交进数据库,保持格式不变
  • 新手问题:在jsp中如何向数据库提交数据?
  • jsp读取数据库中子短的错误。急!!!在线等待!!!给分!!!
  • 求救:一个用jsp和java连接数据库时产生的错误

关键词

得分解答快速导航

  • 帖主:standout
  • realyfly
  • zhjx_10
  • scarab
  • wjfxiao
  • littleyy

相关链接

  • CSDN Java频道
  • Java类图书
  • Java类源码下载

广告也精彩

反馈

请通过下述方式给我们反馈
反馈
提问
网站简介|广告服务|VIP资费标准|银行汇款帐号|网站地图|帮助|联系方式|诚聘英才|English|问题报告
北京创新乐知广告有限公司 版权所有, 京 ICP 证 070598 号
世纪乐知(北京)网络技术有限公司 提供技术支持
Copyright © 2000-2008, CSDN.NET, All Rights Reserved
GongshangLogo