Topic: 连接数据库错误(The value for the useBean class attribute .. is invalid)

  Print this page

1.连接数据库错误(The value for the useBean class attribute .. is invalid) Copy to clipboard
Posted by: linkeca
Posted on: 2005-10-04 23:33

Original Subject : 连接数据库错误,请大侠帮忙

进入BeanDB.jsp页面时 出现了错误:小弟是初学者,请各侠多多指点!!
type Exception report

message

description The server encountered an internal error () that prevented it from fulfilling this request.

exception

org.apache.jasper.JasperException: /DB/BeanDB.jsp(5,0) The value for the useBean class attribute BeanLink.DBBean is invalid.
  org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:39)
  org.apache.jasper.compiler.ErrorDispatcher.dispatch(ErrorDispatcher.java:409)
  org.apache.jasper.compiler.ErrorDispatcher.jspError(ErrorDispatcher.java:150)
  org.apache.jasper.compiler.Generator$GenerateVisitor.visit(Generator.java:1227)
  org.apache.jasper.compiler.Node$UseBean.accept(Node.java:1116)
  org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2163)
  org.apache.jasper.compiler.Node$Visitor.visitBody(Node.java:2213)
  org.apache.jasper.compiler.Node$Visitor.visit(Node.java:2219)
  org.apache.jasper.compiler.Node$Root.accept(Node.java:456)
  org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2163)
  org.apache.jasper.compiler.Generator.generate(Generator.java:3272)
  org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:244)
  org.apache.jasper.compiler.Compiler.compile(Compiler.java:470)
  org.apache.jasper.compiler.Compiler.compile(Compiler.java:451)
  org.apache.jasper.compiler.Compiler.compile(Compiler.java:439)
  org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:511)
  org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:295)
  org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
  org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
  javax.servlet.http.HttpServlet.service(HttpServlet.java:802)

note The full stack trace of the root cause is available in the Apache Tomcat/5.0.28 logs.

以下是代码:

1、DBLink.htm
<!--DBLink.htm-->
<html>
<head><title>Bean Link</titel>
</head>
<h3 align="center">Bean 连接数据库实例</h3>
<h3 align="center">缺省值给出<h3>
<form action=BeanDB.jsp method=post>
<table align="center">
<tr>
<td>请输入驱动程序:</td>
<td><input type=text name=driver value="sun.jdbc.odbc.JdbcOdbcDriver" size=40></td>
</tr>
<tr>
<td>请输入连接:</td>
<td><input type=text name=conn value=jdbc:odbc:MyDb ></td>
</tr>
<tr>
<td>请输入用户名:</td>
<td><input type=text name=suser value=admin ></td>
</tr>
<tr>
<td>请输入密码:</td>
<td><input type=text name=pass value=admin></td>
</tr>
<tr>
<td>请输入查询语句:</td>
<td><input type=text name=sel value="select * from class"></td>
</tr>
<tr>
<td><input type=submit value=submit></td>
<td><input type=submit value=reset></td>
</tr>
</table>
</form>
</body>
</html>

2、<!--BeanDB.jsp-->
<%@ page language="java"%>
<%@ page import="java.sql.*" %>
<%@ page import="BeanLink.DBBean" %>
<jsp:useBean id="TBean" class="BeanLink.DBBean" scope="session" />
<%--完成一些简单的设置--%>
<html>
<head><title>Bean操作数据库</title>
</head>
<body>
<font size=4>
这里显示的数据是由JSP使用JAVABEAN组件获取的
<%
//获取HTML表单传送的参数
String sdriver=request.getParameter("driver);
String sconn=reququest.getParameter("conn");
String suser=reququest.getParameter("user");
String spass=reququest.getParameter("pass");
String sselect=reququest.getParameter("sel");
//这里应该进行参加表单是否为空的判断
if
((sdriver!=null&&sdriver!="")&&(sconn!==nuu&&sconn!="")&&(select!=null&&sselect!=""))
{
if(!TBean.Initialization(sdriver,sconn,suser,spass))
{%>
<%=TBean.getHint()%>
<%}
else
{%>
<% Result=TBean.executeQuery(sselect);%>
<% int j=rs.getMetaData().getColnumName(i)%></td>
<table border="1">
<tr>
<% for(int i=1;i<+j;i++)
{%>
<td><% rs.getMetaData.getColumnName(i)%></td>
<%}%>
</tr>
<% while(rs.next())
{%>
<tr>
<% for(int i=1;i<=j;i++)
{%>
<td><%rs.getString(i)%></td>
<%}%>
</tr>
<% } %>
</table>
<%}
if(!TBean.closeConn())
{%>
<%TBean.getHint)%>
<%}}
else
{
out.println("there is something that is null."};}
%>
</font>
</body>
</html>

3、package BeanLink;

import java.text.*;
import java.util.*;
import java.sql.*;
import java.io.*;
public class DBBean
{
String sDBDriver="";
String sConnStr="";
String suser="";//用户名
String spass="";//密码
String sHint="";//提示信息
ResultSet rs=null;//结果数据集
Connection conn=null;
Statement stmt=null;
//返回提示信息
public String getHint()
{
return sHint;
}
//设置数据库驱动
public void setDBDriver(String s)
{
sDBDriver=""+s;
}
//返回数据库驱动
public String getDBDriver()
{
return sDBDriver;
}
//设置数据库连接
public void setConnnStr(String s)
{
sConnStr=""+s;
}
//返回数据库连接
public String getConnStr()
{
return sConnStr;
}
//返回结果集
public ResultSet getResultSet()
{
return rs;
}
//初始化数据库
public boolean Initialization(String dbDriver,String dbConn,String user,String pass)
{
//设置驱动,连接,用户名及密码的值
sDBDriver=dbDriver;
sConnStr=dbConn;
suser=user;
spass=pass;
try{
Class.forName(sDBDriver);
sHint="Initialization suceefully";
return true;
}catch(java.lang.ClassNotFoundException e)
{
sHint="Initialization :"+e.getMessage();
return false; }
}
//执行SQL语句,返回一个数据库
public ResultSet executeQuery(String sql)
{
rs=null;
try
{
conn=DriverManager.getConnection(sConnStr,suser,spass);
stmt=conn.createStatement();
rs=stmt.executeQuery(sql);
}catch(SQLException ex)
{
sHint="executeQuery:"+ex.getMessage();
}
return rs;
}
//另一个执行SQL语句操作,但不返回数据集
public boolean executeUpdate(String sql)
{
try
{
conn=DriverManager.getConnection(sConnStr,suser,spass);
stmt=conn.createStatement();
stmt.executeUpdate(sql);
return true;
}catch(SQLException ex)
{
sHint="executeUpdate:"+ex.getMessage();
return false;
}
}
//正常关闭所有连接
public boolean closeConn()
{
try{
if(rs!=null)
rs.close();
if(stmt!=null)
stmt.close();
if(conn!=null)
conn.close();
return true;
}catch(SQLException ex)
{
sHint="closeConn:"+ex.getMessage();
return false;
}
}
}

2.Re:连接数据库错误(The value for the useBean class attribute .. is invalid) [Re: linkeca] Copy to clipboard
Posted by: why
Posted on: 2005-10-07 20:32

Where did you deploy your DBBean.class ?

check this for more info:
详解 Tomcat: The value for the useBean class attribute is invalid 问题
http://groups.google.com/group/programmercafe/browse_thread/thread/379cf84cd4615203/eeb1f45e2d79bc32%23eeb1f45e2d79bc32


   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923