創(chuàng)新互聯(lián)www.cdcxhl.cn八線動(dòng)態(tài)BGP香港云服務(wù)器提供商,新人活動(dòng)買多久送多久,劃算不套路!
此次簡單的操作將數(shù)據(jù)從數(shù)據(jù)庫導(dǎo)出生成excel報(bào)表以及將excel數(shù)據(jù)導(dǎo)入數(shù)據(jù)庫
首先建立數(shù)據(jù)庫的連接池:
package jdbc; import java.io.FileInputStream; import java.sql.Connection; import java.util.Properties; import org.apache.commons.dbcp.BasicDataSource; public class BaseDAO { private static BasicDataSource ds; static{ try { //1.讀取配置文件conf.properties,采用java.util.Properties來讀取 Properties p=new Properties(); //2.通過文件流讀取并解析配置文件內(nèi)容,本地?cái)?shù)據(jù)庫用的mysql,所以把配置文件mysql的配置放開,其他數(shù)據(jù)庫配置注釋 p.load(new FileInputStream("src/jdbc.properties")); String driverName=p.getProperty("jdbc.driverClassName");//獲取驅(qū)動(dòng)名稱 String url=p.getProperty("jdbc.url");//獲取數(shù)據(jù)庫的url String user=p.getProperty("jdbc.username");//用戶名 String password=p.getProperty("jdbc.password");//密碼 int maxActive=Integer.parseInt(p.getProperty("jdbc.maxActive"));//獲取大連接數(shù) int maxWait=Integer.parseInt(p.getProperty("jdbc.maxWait"));//獲取大等待時(shí)間 //3.創(chuàng)建一個(gè)連接池 ds=new BasicDataSource(); ds.setDriverClassName(driverName);//設(shè)置驅(qū)動(dòng)名稱 ds.setUrl(url);//設(shè)置數(shù)據(jù)庫地址 ds.setUsername(user);//設(shè)置用戶名 ds.setPassword(password);//設(shè)置密碼 ds.setMaxActive(maxActive);//設(shè)置大連接數(shù) ds.setMaxWait(maxWait);//設(shè)置大等待時(shí)間 } catch (Exception e) { e.printStackTrace(); } } public static Connection getConnection() throws Exception { try { return ds.getConnection(); } catch (Exception e) { System.out.println("連接數(shù)據(jù)庫異常"); throw e; } } public static void close(Connection conn){ if(conn!=null){ try { conn.close(); } catch (Exception e) { e.printStackTrace(); } } } }
分享題目:java生成excel報(bào)表文件示例-創(chuàng)新互聯(lián)
分享網(wǎng)址:http://www.chinadenli.net/article18/dhcjdp.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供品牌網(wǎng)站設(shè)計(jì)、建站公司、定制網(wǎng)站、標(biāo)簽優(yōu)化、網(wǎng)站維護(hù)、域名注冊
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容