Sourav Mukherji

Greenhorn
+ Follow
since Jun 19, 2010
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Sourav Mukherji

can any body write down the steps how to implement it?
13 years ago
How to solve the problem?
is it run through weblogic 8.1?

The problem is bellow:

I create a class file: bellow the code

import java.sql.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class dataConn implements ServletContextListener {

Connection con;
public void contextInitialized(ServletContextEvent sce) {
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con=DriverManager.getConnection("Jdbc:Odbc:test123","test","pass");//for mysql
}
catch(Exception ex) {
//out.println("Error");
}
sce.getServletContext().setAttribute("Connection",con);
}
public void contextDestroyed(ServletContextEvent sce) {
try {
con.close( );
}
catch(Exception ex) {
}
}
}

I call the class file through jsp, the jsp code is bellow

<%@ page contentType="text/html; charset=utf-8" language="java" import="java.sql.*" errorPage="" %>

<%
String mempid="";
String mempname="";
%>
<%!
Connection con=null;
ResultSet rs1=null;
PreparedStatement ps=null;
%><head>
</head>
<%
try {
con=(Connection)getServletContext().getAttribute("Connection");
ps=con.prepareStatement("select empid,empname FROM emp_mast");
rs1=ps.executeQuery();
while(rs1.next()){
mempid=rs1.getString("empid");
mempname=rs1.getString("empname");
out.println(mempid+" "+mempname+"<br>");
}
}catch(Exception ex1){
}

%>

I add a listner in web.xml -

<listener>
<listener-class>
dataConn
</listener-class>
</listener>

and place the class in class folder

It runs well at tomcat 5.5 server

but when i want to run weblogic 8.1 , it shows error in
con=(Connection)getServletContext().getAttribute("Connection");of my jsp
getServletContext() - ERROR : no method with this name could be found at this location
How to solve the problem?
13 years ago