SingleThread
http://skaiste.elekta.lt/Books/O'Reilly/Bookshelfs/books/javaenterprise/servlet/ch03_04.htm
import java.io.*;
import java.sql.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class SingleThreadConnection extends HttpServlet
implements SingleThreadModel {

Connection con = null; // database connection, one per pooled servlet instance

public void init(ServletConfig config) throws ServletException {
super.init(config);

// Establish the connection for this instance
con = establishConnection();
con.setAutoCommit(false);
}

public void doGet(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException {
res.setContentType(
"text/plain");
PrintWriter out = res.getWriter();

// Use the connection uniquely assigned to this instance
Statement stmt = con.createStatement();

// Update the database any number of ways

// Commit the transaction
con.commit();
}

public void destroy() {
if (con != null) con.close();
}

private Connection establishConnection() {
// Not implemented. See Chapter 9, "Database Connectivity".
}
}



hofman   2005-11-19 22:15:35 评论:0   阅读:1090   引用:0

发表评论>>

署名发表(评论可管理,不必输入下面的姓名)

姓名:

主题:

内容: 最少15个,最长1000个字符

验证码: (如不清楚,请刷新)

Copyright@2004-2010 powered by YuLog