tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Koen Dejonghe" <koen_dejon...@hotmail.com>
Subject Re: JDBC and permanent connections
Date Fri, 19 May 2000 17:20:06 GMT
Michael,

I'm attaching some code which I hope will be useful.

Regards,
Koen.

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

public final class YourClass extends HttpServlet {

Connection con = null;
int iMode = 0;

public void init() throws ServletException {

  String url = getServletContext().getInitParameter("url");
  String uid = getServletContext().getInitParameter("uid");
  String pwd = getServletContext().getInitParameter("pwd");

  try {
    //Register the JDBC driver
    Class.forName("oracle.jdbc.driver.OracleDriver");
  } catch( Exception e ) {
    e.printStackTrace();
  }//end catch

  //Get a connection to the database
  try {
    con = DriverManager.getConnection(url, uid, pwd);
  } catch( Exception e ) {
    e.printStackTrace();
  }//end catch

}//end init()

public void destroy() {
  try {
    //Close the connection to the database
    con.close();
  } catch( Exception e ) {
    e.printStackTrace();
  }
}

public void doGet(HttpServletRequest req,
                  HttpServletResponse res)
throws ServletException, IOException{

  try {

    // Set the content type of the data to be sent back
    // to the client.
    res.setContentType("text/html");

    getParameterInfo (req);

    switch (iMode){
    case 0: printViewTable(req, res);
	    break;
    case 1: printInsRecord(req, res);
	    break;
    case 2: printModRecord(req, res);
	    break;
    case 3: printDelRecord(req, res);
	    break;
    }

  }catch( Exception e ) {
    e.printStackTrace();
  }//end catch

}//end doGet()

...
________________________________________________________________________
Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com


Mime
View raw message