Connection Bean Instance Problem..

Hi,

I have a package ConnectionManager, I make an instance of it using <jsp:usebean id="CM" class="db.ConnectionManager" scope="request"/>

I am trying to call a global fuction in my jsp which returns a string. When I call path(someFilename) then this global function try to use instance CM by (CM.getConnection()) method. I am getting error here, I think my global function is not able to use the bean instance. Is there any other way to use the connection bean? What is the right approach? I can access my bean from jsp but not from a global function.

My Code:

<%@ page language="java" import="java.io.*,java.util.*,java.sql.*,java.lang.Object.*"%>

<jsp:useBean class="db.ConnectionManager" scope="request" id="CM" />

<html>

<body>

<h1>Connection Manager Test</h1>

<%!

public String path(String filename){

Connection conn2 = CM.getConnection();

String template_path, strSQL;

Statement stmt = conn2.createStatement();

strSQL = "select t.path from ws_template as t join ws_page as p on t.id = p.template_id where p.path = '"+filename+"' and p.status >= 1000 and t.status >= 1000";

ResultSet rs = stmt.executeQuery(strSQL);

if (rs != null) {

while (rs.next()){

template_path = rs.getString("path");

}

}

else

{

}

rs.close();

conn2.close ();

return template_path;

}

%>

<%=path("About-Us")%>

</body>

</html>

My Error

org.apache.jasper.JasperException: Unable to compile class for JSP

An error occurred at line: -1 in the jsp file: null

Generated servlet error:

[javac] Compiling 1 source file

C:\tomcat\tomcat-4-1-18\work\Standalone\localhost\_\test_dbBean_jsp.java:18: cannot resolve symbol

symbol : variable CM

location: class org.apache.jsp.test_dbBean_jsp

Connection conn2 = CM.getConnection();

^

1 error

[2045 byte] By [San2809a] at [2007-11-27 9:07:46]
# 1
Connection conn2 = ((db.ConnectionManager)request.getAttribute("CM")).getConnection(); http://java.sun.com/products/jsp/tags/11/syntaxref11.fm14.html
java_2006a at 2007-7-12 21:44:58 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 2

This Worked for me. Thanks Everyone..

<%@ page language="java" import="java.io.*,java.util.*,java.sql.*,java.lang.Object.*"%>

<%@ page import="db.ConnectionManager"%>

<html>

<body>

<h1>Connection Manager Test</h1>

<%!

String template_path, strSQL;

public String path(String filename){

try {

ConnectionManager CM = new ConnectionManager();

Connection conn2 = CM.getConnection();

Statement stmt = conn2.createStatement();

strSQL = "select t.path from ws_template as t join ws_page as p on t.id = p.template_id where p.path = '"+filename+"' and p.status >= 1000 and t.status >= 1000";

ResultSet rs = stmt.executeQuery(strSQL);

if (rs != null) {

while (rs.next()){

template_path = rs.getString("path");

}

}

else

{

}

rs.close();

conn2.close ();

}

catch (SQLException e){

System.out.print(e.getMessage());

}

return template_path;

}

%>

<%=path("About-Us")%>

</body>

</html>

San2809a at 2007-7-12 21:44:58 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...