一段servlet代码,谁帮我看一下!

gwangjava 2004-10-22 08:42:23
import java.sql.*;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import sun.misc.*;
import java.util.*;
import com.javaexchange.dbConnectionBroker.*;

/**
* Basic example of the DbConnectionBroker.
* Servlet simply queries a timestamp from an Oracle database and
* displays it with the ID of the current connection from the pool.
* It is invoked by the URL http://whatever-domain/servlet/Example1
*/
public class Example1 extends HttpServlet {
DbConnectionBroker myBroker;

public void init (ServletConfig config) throws ServletException {
super.init(config);
// The below statement sets up a Broker with a minimun pool size of 2 connections
// and a maximum of 5. The log file will be created in
// D:\JavaWebServer1.1\DCB_Example.log and the pool connections will be
// restarted once a day.
try {myBroker = new DbConnectionBroker("oracle.jdbc.driver.OracleDriver",
"jdbc:oracle:thin:@209.94.3.212:1526:orcl",
"scott","tiger",2,6,
"D:\\JavaWebServer1.1\\DCB_Example1.log",0.01);
} catch (IOException e5) {
}
}

public void doGet (
HttpServletRequest request,
HttpServletResponse response
) throws ServletException, IOException {
PrintStream out = new PrintStream (response.getOutputStream());
Connection conn = null;
Statement stmt = null;
int thisConnection;
response.setContentType ("text/html");

try {
// Get a DB connection from the Broker
conn = myBroker.getConnection();

thisConnection = myBroker.idOfConnection(conn);

out.println("<h3>DbConnectionBroker Example 1</h3>" +
"Using connection " + thisConnection +
" from connection pool<p>");

stmt = conn.createStatement();
ResultSet rset = stmt.executeQuery("select sysdate from dual");

while (rset.next()) {
out.println("Time queried from the Database is " + rset.getString(1));
}
} catch (SQLException e1) {
out.println("<i><b>Error code:</b> " + e1 + "</i>");
} finally {
try{if(stmt != null) {stmt.close();}} catch(SQLException e1){};

// The connection is returned to the Broker
myBroker.freeConnection(conn);
}

out.close();
response.getOutputStream().close();
}
}

代码中的super.init(config);是什么意思?有什么功能?
...全文
132 5 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
shaopin 2004-10-22
  • 打赏
  • 举报
回复
Config是servlet在web.xml中配置的相关参数的一个ServletConfig类型的参数
给你一篇文章:
http://dev.csdn.net/article/37/37666.shtm
易点互联 2004-10-22
  • 打赏
  • 举报
回复
ServletConfig:安字面理解
gwangjava 2004-10-22
  • 打赏
  • 举报
回复
那么config指的是什么?
易点互联 2004-10-22
  • 打赏
  • 举报
回复
调用基类的init(),对servlet做初始化,在你给的这个程序里,它加载了驱动myBroker = new DbConnectionBroker("oracle.jdbc.driver.OracleDriver",
"jdbc:oracle:thin:@209.94.3.212:1526:orcl",
"scott","tiger",2,6,
"D:\\JavaWebServer1.1\\DCB_Example1.log",0.01);
redlaputa 2004-10-22
  • 打赏
  • 举报
回复
super.init(config);
父类初始化
也就是说HttpServlet 先执行init

81,122

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧