回 帖 发 新 帖 刷新版面

主题:jsp访问SQL Server数据库出现了好怪的问题?咋办?

我在做用jsp访问SQL Server数据库时,能够向一张表中插入数据,但不能把该表用jsp显示出来(插入与返回该表所有行都在同一程序中),同时Tomact服务器会出现运行错误,我感到好奇怪哦,Tomact服务器在提示有错误前提下竟然还能向表中插入数据。我怎么改也改不出来,我的源代码与错误如下:希望大家帮我看看,谢谢!
<html>
<head>
<title>通过JDBC-ODBC桥访问数据库</title>
</head>
<%@ page contentType="text/html;charset=GB2312" %>
<%@ page import="java.sql.*" %>
<body>
<h2>
通过JDBC-ODBC桥访问数据库
</h2>
<table border=1 align="center">
  <tr>
    <td>fistname</td>
    <td>lastname</td>
    <td>age</td>
    <td>address</td>
    <td>city</td>
  </tr>
<%
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
String url="jdbc:odbc:wzgl";
String username="sa";
String password="";
String s1="insert into employee values('wu','jun',20,'被竟路','wuhan')";
String s2="select * from employee order by age";
Connection con=DriverManager.getConnection(url,username,password);
Statement stmt=con.createStatement();
stmt.executeUpdate(s1);
ResultSet rs=stmt.executeQuery(s2);
while(rs.next())
{
%>
  <tr>
    <td><%=rs.getString("firtname")%></td>
    <td><%=rs.getString("lastname")%></td>
    <td><%=rs.getString("age")%></td>
    <td><%=rs.getString("address")%></td>
    <td><%=rs.getString("city")%></td>
  </tr>
<%    
}
rs.close();
stmt.close();
con.close();

%>
</table>
</body>
</html>

回复列表 (共4个回复)

沙发

Tomact提示错误如下:
错误如下:
org.apache.jasper.JasperException: Column not found
    at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:254)
    at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:295)
    at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:241)
    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:256)
    at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
    at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
    at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
    at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
    at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
    at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
    at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2422)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:180)
    at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
    at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.java:171)
    at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:163)
    at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
    at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
    at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:174)
    at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
    at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
    at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
    at org.apache.coyote.tomcat4.CoyoteAdapter.service(CoyoteAdapter.java:199)
    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:828)
    at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:700)
    at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:584)
    at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:683)
    at java.lang.Thread.run(Thread.java:534)


板凳

<%=rs.getString("age")%>
这句是不是错了?
age是数字型的,是不是不能用getString?
我对JSP也是初学哈

3 楼

getString里的字段名是否有错误?检查一下

4 楼

上面两位朋友的说法对吗,那应该要看他建表是age是用什么类型的吧

我来回复

您尚未登录,请登录后再回复。点此登录或注册