这是我的JAVABEAN:/*
 * Created on 2005-9-16
 *
 * TODO To change the template for this generated file go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
//做一个连接数据库的JAVABEAN
package project;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
/**
 * @author Administrator
 *
 * TODO To change the template for this generated type comment go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
public class ConnDB {

String url="jdbc:oracle:thin:@192.168.1.20:1521:SHINANS";
String user = "snd";
String password = "snd";
Connection conn;
ResultSet rs;
int in;
public ConnDB(){

}
public ResultSet query(String sql){
try{
Class.forName("oracle.jdbc.driver.OracleDriver").newInstance();
    conn= DriverManager.getConnection(url,user,password); 
Statement stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE); 
rs=stmt.executeQuery(sql); 
}catch(Exception e){
e.printStackTrace();
}
return rs;
}
public void update(String sql){
try{
conn = DriverManager.getConnection(url,user,password);
Statement stm = conn.createStatement();
stm.executeUpdate(sql);
}catch(Exception e){
e.printStackTrace();
}
}
/*public int count(){
try{
conn = DriverManager.getConnection(url,"snd","snd");
Statement stm = conn.createStatement();
String c = "select count(*) from test";
ResultSet res = stm.executeQuery(c);
res.next();
in = res.getInt(1);
}catch (Exception e){
e.printStackTrace();
}
return in;
}*/}

解决方案 »

  1.   

    这是那个JSP页面:
    <%@ page contentType="text/html; charset=gb2312" language="java" import="java.util.*" %><%
    String path = request.getContextPath();
    String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
    %><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
      <head>
        <base href="<%=basePath%>">
        
        <title>审核物资能源</title>
        
        <meta http-equiv="pragma" content="no-cache">
        <meta http-equiv="cache-control" content="no-cache">
        <meta http-equiv="expires" content="0">
        <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
        <meta http-equiv="description" content="This is my page">
        
        <STYLE type="text/css">
    <!--
    .style1 {color: #0000FF}
    -->

       
        </STYLE>
      </head>
      <%@ page import="java.sql.* " %>
      <jsp:useBean id="conn" scope="page" class="project.ConnDB"/>
      <body bgcolor="#e0d0f0">
      <FORM name="form1" method="post" action="">
       <H1 align="center" class="style1">审核物资能源</H1>
    <TABLE width="100%" border="1" align="center">
    <TR>
    <TD colspan="12" bgcolor="#0099FF">&nbsp;</TD>
    </TR>
    <TR>
    <TD>物资编号</TD>
    <TD>物资名称</TD>
    <TD>规格型号</TD>
    <TD>目录单价</TD>
    <TD>计量单位</TD>
    <TD>数   量</TD>
    <TD>金   额</TD>
    <TD>提报日期</TD>
    <TD>支出科目</TD>
    <TD>接收状况</TD>
    <TD>审核状况</TD>
    </TR>
    <%
    String sql = "select * from p_m_pm_pay";
    ResultSet rs = conn.query(sql);
    while(rs.next()){
    %>
    <TR>
    <TD><%=rs.getString("mtCode")%></TD>
    <TD><%=rs.getString("mtName")%></TD>
    <TD><%=rs.getString("specType")%></TD>
    <TD><%=rs.getString("listPrice")%></TD>
    <TD><%=rs.getString("measureUnit")%></TD>
    <TD><%=rs.getString("number1")%></TD>
    <TD><%=rs.getString("allMoney")%></TD>
    <TD><%=rs.getString("referDate")%></TD>
    <TD><%=rs.getString("accounts")%></TD>
    <TD><%=rs.getString("flag1")%></TD>
    <TD><%=rs.getString("flag2")%></TD>
    </TR>
    <%}%>
    </TABLE>
    <P align="left" class="style1">
    审核员 <SELECT name="shy"></SELECT>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    审核日期 
    <LABEL>
    <INPUT type="text" name="shrq">
    </LABEL>
    </P>
    <P align="left" class="style1"><LABEL>
    备注 <TEXTAREA name="bz"></TEXTAREA>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;

    <INPUT type="submit" name="sh" value="审核" bgcolor="#0044FF">
    </LABEL>
      
    </p>

      </FORM>

      </body>
    </html>
      

  2.   

    还有要说明的一点就是,如果我不用JAVABEAN ,而是直接在JSP页面中写连接数据库的语句就不会出现问题,所以比较不解.
      

  3.   

    我的WEB.XML是:
    <?xml version="1.0" encoding="UTF-8"?>
    <web-app version="2.4" 
    xmlns="http://java.sun.com/xml/ns/j2ee" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee 
    http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"></web-app>应该改哪?
      

  4.   

    检查你的javabean位置放没放错?
      

  5.   

    到work\Catalina\localhost\org.apache.jsp.shwzny_jsp._jspService文件夹里,找shwzny_jsp.java,看它的第111行,再看它对应shwzny.jsp的哪一行,错误就发生在那里。
      

  6.   

    上面写错了,应该使:到work\Catalina\localhost\×××\org.apache.jsp.shwzny_jsp._jspService文件夹里,找shwzny_jsp.java,看它的第111行,再看它对应shwzny.jsp的哪一行,错误就发生在那里。
      

  7.   

    他那里面说是我的while(rs.next()){}出的错,怎么回事?