Java开发网 Java开发网
注册 | 登录 | 帮助 | 搜索 | 排行榜 | 发帖统计  

您没有登录

» Java开发网 » Database/JDBC/SQL/JDO/Hibernate » MS SQL  

按打印兼容模式打印这个话题 打印话题    把这个话题寄给朋友 寄给朋友    该主题的所有更新都将Email到你的邮箱 订阅主题
flat modethreaded modego to previous topicgo to next topicgo to back
作者 连接数据库错误(The value for the useBean class attribute .. is invalid)
linkeca





发贴: 15
积分: 0
于 2005-10-04 23:33 user profilesend a private message to usersend email to linkecasearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
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;
}
}
}


why edited on 2005-10-07 20:19


话题树型展开
人气 标题 作者 字数 发贴时间
9658 连接数据库错误(The value for the useBean class attribute .. is invalid) linkeca 6064 2005-10-04 23:33
8340 Re:连接数据库错误(The value for the useBean class attribute .. is invalid) why 258 2005-10-07 20:32

flat modethreaded modego to previous topicgo to next topicgo to back
  已读帖子
  新的帖子
  被删除的帖子
Jump to the top of page

   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