一段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);是什么意思?有什么功能?
...全文
104 点赞 收藏 5
写回复
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
回复
发动态
发帖子
Web 开发
创建于2007-09-28

7.9w+

社区成员

Java Web 开发
申请成为版主
社区公告
暂无公告