这个错是什么意思?请帮帮入门者。。。(100分)

  • 主题发起人 主题发起人 119110
  • 开始时间 开始时间
1

119110

Unregistered / Unconfirmed
GUEST, unregistred user!
环境:tomcat + jdk (都是jb自带的)。opendb.java和test.jsp都在jb自带的tomcat的
/webapps/examples/jsp下。win2k 访问sql server2000,已建立一ODBC连接:jsptest
详细情形如下:
1:opendb.java
package opendb;
import java.sql.*;
public class opendb
{
String sDBDriver = "sun.jdbc.odbc.JdbcOdbcDriver";
String sConnStr = "jdbc:odbc:jsptest";
Connection conn = null;
ResultSet rs = null;

public opendb( )
{
try
{
Class.forName(sDBDriver);
}
catch(java.lang.ClassNotFoundException e)
{
System.err.println("opendb( ):'" + e.getMessage( ));
}
}
public ResultSet executeQuery(String sql)
{
rs = null;
try
{
conn = DriverManager.getConnection(sConnStr);
Statement stmt = conn.createStatement( );
rs = stmt.executeQuery (sql);
}
catch(SQLException ex)
{
System.err.println("aq.executeQuery:" + ex.getMessage( ));
}
return rs;
}
}
2:使用javac编译opendb.java生成opendb.class成功。
3:test.jsp
<%@ page language="java" import="java.sql.*"%>
<jsp:useBean id="opendb" scope="page" class="opendb"/>
<%
String sql="select * from dept";
ResultSet rs=jsptest.executeQuery(sql);
out.print("<pre>"+rs.getString("Name")+"</pre> ");
rs.close();
%>
4:运行tomcat成功,在IE中输入:http://localhost:8080/examples/jsp/test.jsp。报错如下:
Generated servlet error:
D:/JBuilder7/jakarta-tomcat-4.0.3/work/localhost/examples/jsp/test$jsp.java:61: Class org.apache.jsp.opendb not found.
opendb opendb = null;
^
An error occurred at line: 2 in the jsp file: /jsp/test.jsp
Generated servlet error:
D:/JBuilder7/jakarta-tomcat-4.0.3/work/localhost/examples/jsp/test$jsp.java:64: Class org.apache.jsp.opendb not found.
opendb= (opendb)
^
An error occurred at line: 2 in the jsp file: /jsp/test.jsp
Generated servlet error:
D:/JBuilder7/jakarta-tomcat-4.0.3/work/localhost/examples/jsp/test$jsp.java:69: Class org.apache.jsp.opendb not found.
opendb = (opendb) java.beans.Beans.instantiate(this.getClass().getClassLoader(), "opendb");
^
An error occurred between lines: 3 and 8 in the jsp file: /jsp/test.jsp
Generated servlet error:
D:/JBuilder7/jakarta-tomcat-4.0.3/work/localhost/examples/jsp/test$jsp.java:90: Undefined variable or class name: jsptestdb0
ResultSet rs=jsptestdb0.executeQuery(sql);
请问什么意思,怎么改啊?
 
class="opendb"
是不是路径指定错了?
试试class="opendb.*"
 
谢谢楼上那位朋友。
问题我已经完全解决了。在网上遇到了一位很好的朋友,得到了他不厌我烦的指导,谢谢。
 
可以把解决方法贴出来,让不懂的看一下。增加经验也好啊
 
你知道為什麼用opendb.*
因為你有用package opendb;這句
可能抄來的,本來這種小段程式直接用public class就好了
引用時也就不用opendb.*,直接用opendb
我一般在產生很多class才考慮分類打包在jar中
opendb.*就是在引用opendb.opendb;
還需多看看java基本知識
 
多人接受答案了。
 
后退
顶部