国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

數據源DBCP的使用

2019-11-06 06:42:53
字體:
來源:轉載
供稿:網友

一、給項目中導jar包

在WEB-INF/lib中導入commons-dbcp.jar、commons.pool-1.5.3.jar、classes12.jar包

二、在src下創建*.PRoperties文件

在文件中寫[plain] view plain copy print?username=scott  passWord=123456  url=jdbc:Oracle:thin:@localhost:1521:orcl  driverClass=oracle.jdbc.driver.OracleDriver  maxActive=100  maxWait=20  
username=scottpassword=123456url=jdbc:oracle:thin:@localhost:1521:orcldriverClass=oracle.jdbc.driver.OracleDrivermaxActive=100maxWait=20

等屬性

三、創建DBUtil.java幫助類

[java] view plain copy print?public class DBUtil {        public static Connection getconn() {          ResourceBundle bundle = ResourceBundle.getBundle(”dbcp”);// 文件名.properties          String username = bundle.getString(”username”);          String password = bundle.getString(”password”);          String url = bundle.getString(”url”);          String driverClass = bundle.getString(”driverClass”);          int maxActive = Integer.parseInt(bundle.getString(“maxActive”));          int maxWait = Integer.parseInt(bundle.getString(“maxWait”));            BasicDataSource dataSource = new BasicDataSource();          dataSource.setUsername(username);          dataSource.setPassword(password);          dataSource.setDriverClassName(driverClass);          dataSource.setMaxActive(maxActive);          dataSource.setUrl(url);          dataSource.setMaxIdle(20);          dataSource.setMaxWait(maxWait);            try {              Connection connection = dataSource.getConnection();              return connection;          } catch (SQLException e) {              e.printStackTrace();          }          return null;      }  }  
public class DBUtil {    public static Connection getconn() {        ResourceBundle bundle = ResourceBundle.getBundle("dbcp");// 文件名.properties        String username = bundle.getString("username");        String password = bundle.getString("password");        String url = bundle.getString("url");        String driverClass = bundle.getString("driverClass");        int maxActive = Integer.parseInt(bundle.getString("maxActive"));        int maxWait = Integer.parseInt(bundle.getString("maxWait"));        BasicDataSource dataSource = new BasicDataSource();        dataSource.setUsername(username);        dataSource.setPassword(password);        dataSource.setDriverClassName(driverClass);        dataSource.setMaxActive(maxActive);        dataSource.setUrl(url);        dataSource.setMaxIdle(20);        dataSource.setMaxWait(maxWait);        try {            Connection connection = dataSource.getConnection();            return connection;        } catch (SQLException e) {            e.printStackTrace();        }        return null;    }}

這些都完成后,這前臺顯示就OK!是不是挺簡單的呢!

[html] view plain copy print?<%          Connection conn = DBUtil.getconn();       %>       <h1><%=conn %></h1>  
<%        Connection conn = DBUtil.getconn();     %>     <h1><%=conn %></h1>


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 崇州市| 长岛县| 通化县| 鹤山市| 柘荣县| 泰来县| 大余县| 常宁市| 五莲县| 枝江市| 静宁县| 扬中市| 江安县| 承德市| 额尔古纳市| 威海市| 武穴市| 行唐县| 天门市| 汝阳县| 张家界市| 那曲县| 潞西市| 家居| 田阳县| 邵阳市| 乌拉特中旗| 五大连池市| 云浮市| 吴桥县| 洛阳市| 勐海县| 磐安县| 梁平县| 鹤岗市| 德清县| 青冈县| 永安市| 鲜城| 临安市| 沁水县|