jsp连接数据库问题(寡人是菜鸟级人物)
连接数据库的bean
package conb;
import java.sql.*;
public class ConnectBean{
private Connection con;
private ResultSet rs;
//类方法 建立数据库连接
public static Connection getConnection() throws
SQLException{
try{Class.forName( "com.microsoft.jdbc.sqlserver.SQLServerDriver ");
}
catch(
ClassNotFoundException e)
{
e.printStackTrace();
}
return DriverManager.getConnection( "jdbc:microsoft:sqlserver:1433;databaseName=myblog ", "sa ", "lluuzhou ");
}
//SQL查询语句
public ResultSet executeQuery(String sql){
Statement st=null;
ResultSet rs=null;
try{
con=ConnectBean.getConnection();
st=con.createStatement();
rs=st.executeQuery(sql);
}
catch(SQLException e)
{
System.err.print(e);
}
return rs;
}
//SQL修改语句
public int executeUpdate(String sql){
Statement st=null;
int rs=0;
try{
con=ConnectBean.getConnection();
st=con.createStatement();
rs=st.executeUpdate(sql);
}
catch(SQLException e)
{
System.err.print(e);
}
finally
{
try{
……
……
//jsp页面文件
<%@page contentType= "text/html;charset=gb2312 " language= "java " import= "java.sql.* "
errorPage= " "%>
<%@page import= "conb.ConnectBean "%>
<jsp:useBean id= "condb " scope= "session " class= "conb.ConnectBean "> </jsp:useBean>
<%
//获取前台登陆信息(姓名、密码)
String user_n=String.valueOf(session.getAttribute( "user_name "));
String pass_w=String.valueOf(session.getAttribute( "pass_word "));
if(user_n!=null&&pass_w!=null)
//连接数据库
//String sql= "SELECT * FROM manage WHERE admin= ' "+user_n+ " 'AND password= ' "+pass_w+ " ' ";
ResultSet rs=condb.executeQuery( "SELECT * FROM manage WHERE admin= ' "+user_n+ " 'AND password= ' "+pass_w+ " ' ");
if(rs.next()){
response.sendRedirect( "manage.jsp ");
}
else{
out.print( "…… ");
}
%>
执行到这个页面的时候就会出错,
org.apache.jasper.JasperException: Unable to compile class for JSP:
An error occurred at line: 12 in the jsp file: /admin/check.j