初写javabean时遇到的问题
demo.jsp
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=gb2312">
<title>客户信息调查</title>
</head>
<body>
<p><b>客户信息调查</b></p>
<%@ page language="java" import="java.sql.*" %>
<jsp:useBean id="DB" scope="page" class="DBconn"/>
<%
ResultSet rs=DB.executeQuery("select * from EG_TASK order by id");
while (rs.next()){
out.print("<LI>"+rs.getString("TASK_NAME")+"<LI>");
out.print("<LI>"+rs.getInt("TASK_LEVEL")+"<LI>");
out.print("<LI>"+StartTime=rs.getDate("TASK_STARTTIME")+"<LI>");
}
rs.close();
%>
</body>
</html>
学习调用javaBean,可是有问题,不知为何?
import java.sql.*;
public class DBconn{
String DBdrive="public PreparedStatement getUpdatedPstmt()";
String ConnStr="jdbc:oracle:thin:@192.168.0.8:1521:develop";
Connection Conn=null;
ResultSet Rs=null;
public DBconn(){
try{
Class.forName(DBdrive);
}catch(ClassNotFoundException e){
System.out.println("DBconn():"+e.getMessage());
}
}
public ResultSet executeQuery(String sql){
Rs=null;
try{
Conn = DriverManager.getConnection(ConnStr, "szhr", "szhr123");
Statement stmt=Conn.createStatement();
Rs=stmt.executeQuery(sql);
}catch(SQLException e){
System.out.println(e.getMessage());
}
return Rs;
}
}
文件的位置都没放错,jsp在tomcat的example下,javabean在web-inf的classes中,可是tomcat提示org.apache.jasper.JasperException: Unable to compile class for JSP
An error occurred at line: 8 in the jsp file: /demo.jsp
Generated servlet error:
[javac] Compiling 1 source file
C:\Program Files\Apache Group\Tomcat 4.1\work\Standalone\localhost\examples\demo_jsp.java:54: cannot resolve symbol
symbol : class DBconn
location: class org.apache.jsp.demo_jsp
DBconn DB = null;
^
An error occurred at line: 8 in the jsp file: /demo.jsp
Generated servlet error:
C:\Program Files\Apache Group\Tomcat 4.1\work\Standalone\localhost\examples\demo_jsp.java:56: cannot resolve symbol
symbol : class DBconn
location: class org.apache.jsp.demo_jsp
DB = (DBconn) pageContext.getAttribute("DB", PageContext.PAGE_SCOPE);
^
An error occurred at line: 8 in the jsp file: /demo.jsp
Generated servlet error:
C:\Program Files\Apache Group\Tomcat 4.1\work\Standalone\localhost\examples\demo_jsp.java:59: cannot resolve symbol
symbol : class DBconn
location: class org.apache.jsp.demo_jsp
DB = (DBconn) java.beans.Beans.instantiate(this.getClass().getClassLoader(), "DBconn");
^
An error occurred at line: 9 in the jsp file: /demo.jsp
Generated servlet error:
C:\Program Files\Apache Group\Tomcat 4.1\work\Standalone\localhost\examples\demo_jsp.java:74: cannot resolve symbol
symbol : variable StartTime
location: class org.apache.jsp.demo_jsp
out.print(""+StartTime=rs.getDate("TASK_STARTTIME")+"");
^
4 errors
为什么呢,搞不懂,希望高手指点!