我在bean中调用时,ServletContext如何加参数?

04-04-23 chinatao
//有一个连接ORACLE的bean,中间有一段是这样的:

public class MyBean

{

.....

public boolean connect(ServletContext servletcontext)

throws ServletException

{

ccimp = (OracleConnectionCacheImpl)servletcontext.getAttribute("CACHE_CONN_UNINET");

if(ccimp == null)

{

..........

}

return true;

}

//在接下调用时总是告诉我参数错:

public synchronized int GetPoint( String name )

throws SQLException

{

String Sql="select point from name_table where name='"+name+"'";

ResultSet rs;

int point=0;

try

{

connect();//也试过用参数:application

Statement statement = mConn2.createStatement();

rs= statement.executeQuery(Sql);

if ( rs.next() )

{

point=rs.getInt(1);

}

rs.close();

}

......

return point;

}

......

}

在jsp中调用是这样的:

......

<jsp:useBean id="testDB" scope="page" class="MyBean" />

......

try

{

testDB.connect(application);//这时的application在bean里面应该用什么?

Sql="select * from name_table";

rs=testDB.doSearch(Sql);

if ( rs.next() )

{

......

}

rs.close();

}catch(Exception e){

out.println("Error:"+e.getMessage());

}finally{

testDB.close();

}

......

这样是正常的。

现在请教各位大侠,我在bean里面调用时,应该用什么参数?

我的平台:TOMCAT 5.0.18+JDK1.4.2+ORACLE 8.1.6i

猜你喜欢