jsp + javabean

jimwalker 2009-03-25 11:04:04
我在编译成class文件后用javabean
<jsp:useBean id="connection" scope="page" class="com.JDBConnection"/>
页面出现以下错误
The value for the useBean class attribute com.JDBConnection is invalid.


请大家帮忙看看以下Java代码 有什么根本的错误
package com;
import java.sql.*;

public class JDBConnection {
private final String dbDriver = "com.microsoft.jdbc.sqlserver.SQLServerDriver"; //连接sql数据库的方法
private final String url = "jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=db_database02";
private final String userName = "sa";
private final String password = "19851130";
private Connection con = null;

public JDBConnection() {
try {
Class.forName(dbDriver).newInstance(); //加载数据库驱动
} catch (Exception ex) {
System.out.println("数据库加载失败");
}
}

//创建数据库连接
public boolean creatConnection() {
try {
con = DriverManager.getConnection(url, userName, password);
con.setAutoCommit(true);

} catch (SQLException e) {
System.out.println(e.getMessage());
System.out.println("creatConnectionError!");
}
return true;
}



//对数据库的查询操作
public ResultSet executeQuery(String sql) {
ResultSet rs;
try {
if (con == null) {
creatConnection();
}
Statement stmt = con.createStatement();
try {
rs = stmt.executeQuery(sql);
} catch (SQLException e) {
System.out.println(e.getMessage());
return null;
}
} catch (SQLException e) {
System.out.println(e.getMessage());
System.out.println("executeQueryError!");
return null;
}
return rs;
}

//关闭数据库的操作
public void closeConnection() {
if (con != null) {
try {
con.close();
} catch (SQLException e) {
e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
System.out.println("Failed to close connection!");
} finally {
con = null;
}
}
}

}
...全文
68 4 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
jimwalker 2009-03-26
  • 打赏
  • 举报
回复
jsp代码如下 帮忙看看


<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" errorPage="" %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<link href="Css/Css.css" rel="stylesheet" type="text/css">
<jsp:useBean id="connection" scope="request" class="com.JDBConnection"/>
<title>把数据库中的记录显示到下拉列表中</title>
</head>

<body>
<table width="100" border="1" align="center" cellpadding="0" cellspacing="0" background="images/00.gif" bordercolordark="#CCCCCC" bordercolorlight="#FFFFFF">
<tr>
<td><form name="form" method="post" >
<table width="565" height="258" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td height="38" colspan="2" valign="bottom" >
<table width="556" height="29" border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="65"> </td>
<td width="491">          添加个人详细信息</td>
</tr>
</table></td>
</tr>
<tr>
<td width="120" height="15">       姓名:</td>
<td width="445" height="20"><input name="user_name" type="text" class="text" size="20"> </td>
</tr>
<tr>
<td height="20">       性别: </td>
<td height="20"><select name="user_sex">
<option value="我是男生">我是男生</option>
<option value="我是女生" selected>我是女生</option>
</select>
</td>
</tr>
<tr>
<td height="20">       生日:</td>
<td height="20"><input name="user_birthday" type="text" class="text" size="30">
<span class="style5">*</span> 如(1984-03-13或1984/03/13)</td>
</tr>
<tr>
<td height="20">       昵称:</td>
<td height="20"><input name="user_nick" type="text" class="text">
同学都是怎么称呼你的?</td>
</tr>
<tr>
<td height="20">     所属班级:</td>
<td height="20">
<select name="user_class" >
<%
String sql="select * from tb_wyClass";
ResultSet rs=connection.executeQuery(sql);
try{
while(rs.next()){
%>
<option value="<%=rs.getString("name")%>"><%=rs.getString("name")%></option>
<%}}catch (Exception e){}%> </select>
</td>
</tr>
<tr>
<td height="20">     通信地址:</td>
<td height="20"><input name="user_address" type="text" class="text" size="35"></td>
</tr>
<tr>
<td height="20">     邮政编码:</td>
<td height="20"><input name="user_size" type="text" class="text"></td>
</tr>
<tr>
<td height="20">     电话号码:</td>
<td height="20"><input name="user_telephone" type="text" class="text" size="30"></td>
</tr>
<tr>
<td height="20">       OICQ:</td>
<td height="20"><input name="user_OICQ" type="text" class="text"></td>
</tr>
<tr>
<td height="20">     个人主页:</td>
<td height="20"><input name="user_homepage" type="text" class="text " size="30"></td>
</tr>
<tr>
<td height="20" colspan="2">               
<input name="button" type="submit" class="button" value="提交" >  
<input name="button" type="reset" class="button" value="重置"></td>
</tr>
</table>
</form></td>
</tr>
</table>
</body>
</html>
oklinsong 2009-03-25
  • 打赏
  • 举报
回复
包路径是不是有问题?
单独的测试一下JDBConnection能不能正常工作,如果能正常工作应该是你calss配置的路径的问题
function_chk 2009-03-25
  • 打赏
  • 举报
回复
把JSP的代码也发上来撒~~
gf173237 2009-03-25
  • 打赏
  • 举报
回复
构造方法里面不能有方法体吧!

81,122

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧