初学者的小问题,我用BEAN写了一个操作类,为什么有错误呢,,,望指点
Operate 类
package org.wdj.bean;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
import javax.naming.InitialContext;
import javax.sql.DataSource;
public class Operate {
private Connection con=null;
private Statement stmt=null;
public Operate(){
try {
javax.naming.Context initCtx=new InitialContext();
con=((DataSource)initCtx.lookup( "java:comp/env/jdbc/test ")).getConnection();
} catch (Exception e) {
// TODO 自动生成 catch 块
e.printStackTrace();
}
}
public ResultSet getRS(String sql)throws Exception{
stmt=con.createStatement();
return stmt.executeQuery(sql);
}
public boolean close()throws Exception{
boolean flag=true;
try{
con.close();
stmt.close();
}
catch(Exception e){
flag=false;
}
return flag;
}
}
MyJsp.jsp页
<%
Operate op=new Operate();
java.sql.ResultSet rs=op.getRS( "select * from test ");
while(rs.next()){
out.println(rs.getString( "username "));
out.println( " <br> ");
}
if(op.close()){
out.println( "true ");
%>
出现错误提示是:
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
org.apache.jasper.JasperException: Unable to compile class for JSP:
------解决方案--------------------都没连数据库的代码。。。。。。写的太混乱了
------解决方案--------------------import org.wdj.bean.Operate;
------解决方案--------------------加上
<jsp:useBean id= "xxx " scope= "page " class= "class文件的路径 " />
------解决方案--------------------看楼主的程序,应该是使用的连接池。
我的异常网推荐解决方案:The server encountered an internal error () that prevented it from fulfilling this request.,http://www.aiyiweb.com/java-web/317.html
我的异常网推荐解决方案:org.apache.jasper.JasperException: Unable to compile class,http://www.aiyiweb.com/j2ee/2308.html