DBUtil.java
资源名称:(J2EE)oa.rar [点击查看]
上传用户:lm2018
上传日期:2015-12-12
资源大小:30449k
文件大小:1k
源码类别:
Jsp/Servlet
开发平台:
Java
- package com.oa.util;
- import java.sql.Connection;
- import javax.naming.Context;
- import javax.naming.InitialContext;
- import javax.sql.DataSource;
- public class DBUtil {
- public static Connection getConn() {
- Connection conn = null;
- try {
- Context context = new InitialContext();
- DataSource dataSource = (DataSource) context
- .lookup("java:comp/env/jdbc/oracle");
- conn = dataSource.getConnection();
- } catch (Exception e) {
- conn = null;
- e.printStackTrace();
- }
- return conn;
- }
- }