/ * * TestServlet.java * created on 2005-1-29 * / package servlet;
Import java.io. *; import java.sql. *; import javax.servlet. *; import javax.servlet.http. *; import db.dbconnectionManager;
/ ** * @author Yewberry * / public class TestServlet extends HttpServlet {private DBConnectionManager connMgr; public void init (ServletConfig conf) throws ServletException {super.init (conf); connMgr = DBConnectionManager.getInstance ();} public void service (HttpServletRequest Req, httpservletresponse res) throws oException {
Res.SetContentType ("text / html; charset = GBK"); Res.SetHeader ("Content-Language", "EN");
String SQL = "Select * from user"; PrintWriter out = res. max, connection con = connmgr.getConnection ("testdb"); if (con == null) {Out.println ("You cannot get database connections." ); //Out.println ("can't Get DB connection! "); Return;} resultset = null; ResultSetMetadata md = null; statement stmt = null; try {stmt = con.createstatement (); rs = stmt .executeQuery (SQL); MD = rs.getMetadata (); out.println ("
Public void destroy () {connmgr.release (); super.destroy ();}}