⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 condb.java

📁 一个简单的班费管理系统
💻 JAVA
字号:
/*
 * condb.java
 *
 * Created on 2007年12月8日, 上午9:44
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package com.classmoney.servlet;

/**
 *
 * @author Administrator
 */
import java.sql.*;

import javax.naming.*;
import javax.sql.DataSource;

public class condb {
//数据库连接文件
        public static synchronized Connection getConnection() {
            try {
                Context envCtx = new InitialContext(); //创建上下文
                DataSource ds = (DataSource) envCtx.lookup("java:/MysqlDs"); //查找数据源,数据源文件在jboo服务器下:jboss\server\default\deploy\mysql-ds.xml


                return ds.getConnection();//返回 连接
            } catch (SQLException e) {
                System.out.println("数据源配置发生错误" + e.toString());
                return null;
            } catch (NamingException e2) {
                System.out.print("数据源配置" + e2.toString());
                return null;
            } 




        }

    

    public static void close(ResultSet rs, Statement st, Connection conn) {
        try {
            if (rs != null)
                rs.close();
        } catch (SQLException ex) {
        }
        ;

        try {
            if (st != null)
                st.close(); 

        } catch (SQLException ex) {
        }
        ;

        try {
            if (conn != null)
                conn.close();
        } catch (SQLException ex) {
        }
        ;
    }
}


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -