惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

T
Threatpost
V
Vulnerabilities – Threatpost
TaoSecurity Blog
TaoSecurity Blog
C
Cybersecurity and Infrastructure Security Agency CISA
P
Proofpoint News Feed
G
GRAHAM CLULEY
S
Securelist
P
Palo Alto Networks Blog
MongoDB | Blog
MongoDB | Blog
A
Arctic Wolf
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
WordPress大学
WordPress大学
Project Zero
Project Zero
T
Threat Research - Cisco Blogs
L
Lohrmann on Cybersecurity
C
Cyber Attacks, Cyber Crime and Cyber Security
F
Fortinet All Blogs
博客园 - 叶小钗
B
Blog RSS Feed
C
Cisco Blogs
Google DeepMind News
Google DeepMind News
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
Apple Machine Learning Research
Apple Machine Learning Research
G
Google Developers Blog
K
Kaspersky official blog
D
Docker
Latest news
Latest news
Cisco Talos Blog
Cisco Talos Blog
T
Tor Project blog
Cyberwarzone
Cyberwarzone
Security Latest
Security Latest
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
D
Darknet – Hacking Tools, Hacker News & Cyber Security
Spread Privacy
Spread Privacy
Microsoft Azure Blog
Microsoft Azure Blog
C
Check Point Blog
J
Java Code Geeks
Simon Willison's Weblog
Simon Willison's Weblog
T
Tenable Blog
Recent Announcements
Recent Announcements
T
Tailwind CSS Blog
H
Help Net Security
L
LINUX DO - 热门话题
T
The Exploit Database - CXSecurity.com
Jina AI
Jina AI
S
SegmentFault 最新的问题
MyScale Blog
MyScale Blog
NISL@THU
NISL@THU
美团技术团队
腾讯CDC

博客园 - xyublog

QMail Problems - xyublog - 博客园 OptorSim cron服务配置祥解 打包war 试了一次ant - xyublog - 博客园 vi命令的全部使用 剖析Xml4C源码,完美兼容中文XML 安装openssl 一个小的WEB项目中的实现方法讨论 内核升级 java socket programming Putty 输入中文 apache和resin整合 RedHat9+Apache2+Resin3 安装指南 利用shell编程实现DOS风格的Linux命令行 一个不得不提的网站安全问题! Linux下的中文显示和支持常见问题解答 强行更改oracle字符集 tomcat安装
RESIN连接池
xyublog · 2005-03-18 · via 博客园 - xyublog

===================

/*****************************
 * 数据库连接 bean ,用来连接 resin 的连接池
 *****************************/
package net.asales.mysql;

import java.sql.Connection;
import java.sql.Statement;
import java.sql.ResultSet;
import java.sql.SQLException;
import javax.sql.DataSource;
import javax.naming.Context;
import javax.naming.InitialContext;

public class DBConnection {
    private Connection conn = null;
    private Statement stmt = null;
    private ResultSet rs = null;
    private int resultNum = 0;

    /**
     * 构造函数
     * 找到数据源,并用这个数据源创建连接
     */
    public DBConnection() {
        try {
            Context env = new InitialContext();
            DataSource pool = (DataSource) env.lookup
        ("java:comp/env/jdbc/asales");
            if (pool == null)
               throw new Exception("jdbc/asales is
         an unknown DataSource");
            conn = pool.getConnection();
            stmt = conn.createStatement();
        } catch (Exception e) {
            System.out.println("naming:" + e.getMessage());
        }
    }

    /**
     * 执行SQL语句:查询记录
     * @param sql SQL语句
     * @return ResultSet 记录集
     */
    public ResultSet executeQuery(String sql) {
        rs = null;
        try {
            rs = stmt.executeQuery(sql);
        } catch(SQLException se) {
            System.out.println("Query error:" + se.getMessage());
        }
        return rs;
    }

    /**
     * 执行SQL语句 :插入与更新记录
     * @param sql SQL语句
     * @return int resultNum 更新的记录数
     */
    public int executeUpdate(String sql) {
        resultNum=0;
        try {
            resultNum = stmt.executeUpdate(sql);
        } catch (SQLException se) {
            System.err.println("Update error:" + se.getMessage());
        }
        return resultNum;
    }

    /**
     * 关闭连接
     */
    public void close() {
        try {
            if (rs != null) {
                rs.close();
                rs = null;
            }
            if (stmt != null) {
               stmt.close();
               stmt = null;
            }
            if (conn != null) {
                conn.close();
                conn = null;
            }
        } catch (SQLException se) {
            System.out.println("close error: " + se.getMessage());
        }
    }
}

===================

以下是RESIN配置文件中关于数据源的配置例:

<resource-ref>
  <res-ref-name>jdbc/asales</res-ref-name>
  <res-type>javax.sql.DataSource</res-type>
  <init-param driver-name="org.gjt.mm.mysql.Driver"/>
  <init-param url="jdbc:mysql://localhost:3306/asales"/>
  <init-param user="root"/>
  <init-param password=""/>
  <init-param max-connections="20"/>
  <init-param max-idle-time="30"/>
</resource-ref>