javabean与SQL数据库连接的问题
org.apache.jasper.JasperException:/check.jsp(3,0)ThevaluefortheuseBeanclassattributed...
org.apache.jasper.JasperException: /check.jsp(3,0) The value for the useBean class attribute database.sqlbean is invalid.
出错如上所示:
<%@page contentType="text/html;charset=gb2312"language="java" errorPage=""%>
<%@page import="java.sql.*"%>
<jsp:useBean id="sqltest" class="database.sqlbean" scope="page">
</jsp:useBean>
<html>
<head>
<title>认证码验证页面</title>
<meta http-equiv="Content-Type"content="text/html;charset=gb2312">
<META HTTP-EQUIV="Pragma" CONTENT="no-cache">
<META HTTP-EQUIV="Cache-Control"CONTENT="no-cache">
<META HTTP-EQUIV="Expires"CONTENT="0">
</head>
<body>
<%
String rand=(String)session.getAttribute("rand");
String input=(String)session.getAttribute("input");
String user_name=(String)session.getAttribute("user_name");
String pass_word=(String)session.getAttribute("pass_word");
%>
系统产生的认证码为:
<%=rand %><br>
您输入的认证码为:
<%=input%><br>
<font color=green>验证码输入相同,认证成功!</font><br>
<br>
您输入的用户名为:
<%=session.getAttribute("user_name")%><br>
密码为:
<%=session.getAttribute("pass_word")%><br>
<%
String permit;
ResultSet rs=null;
String SqlString="select * from UserInfo where username='"+user_name+"'and password='"+pass_word+"'";
try
{
//设置连接
sqltest.setConnection("com.microsoft.jdbc.sqlserver.SQLServerDriver","jdbc:microsoft:sqlserver://localhost:2433;DatabaseName=login","sa","123");
//设置SQL语句
sqltest.setQueryStatement(SqlString);
//得到查询结果
rs=sqltest.getResult();
if(rs.next())
{
out.print("登陆成功");
//获得用户的权限
permit=rs.getString("permit");
if(permit.equals("1"))
{
out.println(":您的权限是管理员组");
}
else
{
out.println(":您的权限是用户组");
}
}
else
{
out.println("登陆失败,用户名或密码错");
}
}
catch(SQLException e1)
{
out.println("SQL异常!");
}
%>
</body>
</html>
朋友说用JAVABEAN要配置XML什么的。我是菜鸟,真的不懂。希望各位大侠帮我看看问题在哪里。怎么改?要配置的话,怎么配置。
package database;
import java.sql.*;
public class sqlbean
{
public String query_statement;//定义SQL语句
public ResultSet result=null;//查询结果数据集
public Connection conn;
//设置SQL查询语句
public void setQuerystatement(String query_statement)
{
this.query_statement=query_statement;
}
//设置连接参数
public void setConnection(String driverName,String jdbcURL,String username,String password) throws Exception
{
Connection conn1;
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
conn1=DriverManager.getConnection("jdbc:microsoft:sqlserver://localhost:2433;DatabaseName=UserInfo","sa","123");
conn1.setAutoCommit(false);
this.conn=conn1;
}
//获取查询结果
public ResultSet getResult()
{
try
{
PreparedStatement select_stm=conn.prepareStatement(query_statement,java.sql.ResultSet.TYPE_SCROLL_INSENSITIVE,java.sql.ResultSet.CONCUR_READ_ONLY);
result=select_stm.executeQuery();
}
catch(Exception e)
{
System.out.println(e);
}
return result;
}
} 展开
出错如上所示:
<%@page contentType="text/html;charset=gb2312"language="java" errorPage=""%>
<%@page import="java.sql.*"%>
<jsp:useBean id="sqltest" class="database.sqlbean" scope="page">
</jsp:useBean>
<html>
<head>
<title>认证码验证页面</title>
<meta http-equiv="Content-Type"content="text/html;charset=gb2312">
<META HTTP-EQUIV="Pragma" CONTENT="no-cache">
<META HTTP-EQUIV="Cache-Control"CONTENT="no-cache">
<META HTTP-EQUIV="Expires"CONTENT="0">
</head>
<body>
<%
String rand=(String)session.getAttribute("rand");
String input=(String)session.getAttribute("input");
String user_name=(String)session.getAttribute("user_name");
String pass_word=(String)session.getAttribute("pass_word");
%>
系统产生的认证码为:
<%=rand %><br>
您输入的认证码为:
<%=input%><br>
<font color=green>验证码输入相同,认证成功!</font><br>
<br>
您输入的用户名为:
<%=session.getAttribute("user_name")%><br>
密码为:
<%=session.getAttribute("pass_word")%><br>
<%
String permit;
ResultSet rs=null;
String SqlString="select * from UserInfo where username='"+user_name+"'and password='"+pass_word+"'";
try
{
//设置连接
sqltest.setConnection("com.microsoft.jdbc.sqlserver.SQLServerDriver","jdbc:microsoft:sqlserver://localhost:2433;DatabaseName=login","sa","123");
//设置SQL语句
sqltest.setQueryStatement(SqlString);
//得到查询结果
rs=sqltest.getResult();
if(rs.next())
{
out.print("登陆成功");
//获得用户的权限
permit=rs.getString("permit");
if(permit.equals("1"))
{
out.println(":您的权限是管理员组");
}
else
{
out.println(":您的权限是用户组");
}
}
else
{
out.println("登陆失败,用户名或密码错");
}
}
catch(SQLException e1)
{
out.println("SQL异常!");
}
%>
</body>
</html>
朋友说用JAVABEAN要配置XML什么的。我是菜鸟,真的不懂。希望各位大侠帮我看看问题在哪里。怎么改?要配置的话,怎么配置。
package database;
import java.sql.*;
public class sqlbean
{
public String query_statement;//定义SQL语句
public ResultSet result=null;//查询结果数据集
public Connection conn;
//设置SQL查询语句
public void setQuerystatement(String query_statement)
{
this.query_statement=query_statement;
}
//设置连接参数
public void setConnection(String driverName,String jdbcURL,String username,String password) throws Exception
{
Connection conn1;
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
conn1=DriverManager.getConnection("jdbc:microsoft:sqlserver://localhost:2433;DatabaseName=UserInfo","sa","123");
conn1.setAutoCommit(false);
this.conn=conn1;
}
//获取查询结果
public ResultSet getResult()
{
try
{
PreparedStatement select_stm=conn.prepareStatement(query_statement,java.sql.ResultSet.TYPE_SCROLL_INSENSITIVE,java.sql.ResultSet.CONCUR_READ_ONLY);
result=select_stm.executeQuery();
}
catch(Exception e)
{
System.out.println(e);
}
return result;
}
} 展开
2个回答
大雅新科技有限公司
2024-11-19 广告
2024-11-19 广告
这方面更多更全面的信息其实可以找下大雅新。深圳市大雅新科技有限公司从事KVM延长器,DVI延长器,USB延长器,键盘鼠标延长器,双绞线视频传输器,VGA视频双绞线传输器,VGA延长器,VGA视频延长器,DVI KVM 切换器等,优质供应商,...
点击进入详情页
本回答由大雅新科技有限公司提供
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询