tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Challa Ramesh Babu <challaram...@yahoo.com>
Subject datasource
Date Fri, 21 Sep 2001 09:07:31 GMT
Hi developers,

this is my program and as I already given the error
that iam encountering.

suggest me where i went wrong and how to solve it.

challa

package datasource;

import com.ibm.ivj.tivoli.*;
import com.ibm.ivj.tivoli.events.*;
import com.ibm.ivj.tomcat.*;
import java.sql.*;
import javax.sql.*;
import java.util.*;
import javax.naming.*;
import java.io.*;

/**
 * Insert the type's description here.
 * Creation date: (9/20/2001 10:39:03 AM)
 * @author: Administrator
 */
public class DatSrcServlet extends
javax.servlet.http.HttpServlet 
{
	
	DataSource ds;
/**
 * Process incoming HTTP GET requests 
 * 
 * @param request Object that encapsulates the request
to the servlet 
 * @param response Object that encapsulates the
response from the servlet
 */
public void
doGet(javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response)
throws javax.servlet.ServletException,
java.io.IOException 
{
	try
	{
		//Hashtable env = new Hashtable();
		
		//env.put(Context.INITIAL_CONTEXT_FACTORY,
"com.sun.jndi.fscontext.RefFSContextFactory");
		//env.put(Context.INITIAL_CONTEXT_FACTORY,
"com.sun.jndi.ldap.LdapCtxFactory");

/*		env.put(Context.INITIAL_CONTEXT_FACTORY,
"javax.naming.ldap.InitialLdapContext");

		env.put(Context.PROVIDER_URL, "");
		env.put(Context.SECURITY_PRINCIPAL, "dbo");
		env.put(Context.SECURITY_CREDENTIALS, "qazwsxed");
*/

/*		
//		Context initCtx = new InitialContext(env);
		Context initCtx = new InitialContext();
		Context envCtx = (Context)
initCtx.lookup("java:comp/env");
//		Context envCtx = (Context)
initCtx.lookup("jdbc/EmployeeDB");
		ds = (DataSource) envCtx.lookup("jdbc/EmployeeDB");
*/
		InitialContext ctx = new InitialContext();
		ds = (DataSource) ctx.lookup("jdbc/EmployeeDB");
	}
	catch(NamingException ne)
	{
		System.out.println("Error in Naming Exception :
"+ne);
	}		
	
	Connection conn = null;
	Statement st = null;
	ResultSet rs = null;
	 
	
	PrintWriter out = response.getWriter();
	response.setContentType("text/html");
	
	try
	{
		conn = ds.getConnection();
	}
	catch(SQLException sqe)
	{
		System.out.println("Error in Connection : "+sqe);
	}

	try
	{	
		st = conn.createStatement();
		rs = st.executeQuery("Select Comp_Id from
tblesysusrmast");
		out.println("<html><head><title>Data Suorce
Pooling</title>");
		out.println("</head><body>");
		out.println("Displaying Records using Datasource");
		
		while(rs.next())
		{
			out.println("rs.getString(1) + <br>");
		}

		out.println("</body></html>");	
	}
	catch(Exception e)
	{
		System.out.println(e);
	}
	
	finally
	{
		try
		{
			if(conn != null)	
	 			conn.close();
		}
		catch(SQLException sql)
		{
			System.out.println("Error in Closing : "+sql);
		}
	}		
}
/**
 * Process incoming HTTP POST requests 
 * 
 * @param request Object that encapsulates the request
to the servlet 
 * @param response Object that encapsulates the
response from the servlet
 */
public void
doPost(javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response)
throws javax.servlet.ServletException,
java.io.IOException {

	//performTask(request, response);
	doGet(request, response);

}
/**
 * Returns the servlet info string.
 */
public String getServletInfo() {

	return super.getServletInfo();

}
/**
 * Insert the method's description here.
 * Creation date: (9/20/2001 10:51:06 AM)
 */
public void init() 
{
	/*try
	{
		Context initCtx = new InitialContext();
		Context envCtx = (Context)
initCtx.lookup("java:comp/env");
		ds = (DataSource) envCtx.lookup("jdbc/EmployeeDB");
	}
	catch(NamingException ne)
	{
		System.out.println("Error in Naming Exception :
"+ne);
	}*/		
}
}


____________________________________________________________
Do You Yahoo!?
Get your free @yahoo.co.uk address at http://mail.yahoo.co.uk
or your free @yahoo.ie address at http://mail.yahoo.ie

Mime
View raw message