新聞中心
這里有您想知道的互聯(lián)網(wǎng)營(yíng)銷(xiāo)解決方案
使用組件實(shí)現(xiàn)JAVA連接Oracle數(shù)據(jù)庫(kù)
下面介紹JAVA連接Oracle數(shù)據(jù)庫(kù)的方法主要以Commons DbUtils組件來(lái)連接數(shù)據(jù)庫(kù)。該JAVA連接Oracle數(shù)據(jù)庫(kù)得方法供您參考,希望對(duì)您能有所幫助。

它將JDBC中的一些類(lèi)進(jìn)行了二次封裝,它不象hibernate(ORMapping)那樣將JAVA對(duì)象與數(shù)據(jù)庫(kù)映射。首先將oracle驅(qū)動(dòng)類(lèi)文件與Commons DbUtils組件的JAR文件一起引入到項(xiàng)目中。
- String sql = "insert into users(username,password) values(?,?)";
- String username = request.getParameter("username");
- String param[]={StringUtil.filterHtml(username),StringUtil.filterHtml(request.getParameter("password"))
- };
- try {
- Context initContext = new InitialContext();
- DataSource ds = (DataSource) initContext.lookup("java:/comp/env/jdbc/oracleds");
- QueryRunner qr = new QueryRunner(ds);
- result = qr.update(sql, param);
- } catch (NamingException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (SQLException e) {
- e.printStackTrace();
- }
文章標(biāo)題:使用組件實(shí)現(xiàn)JAVA連接Oracle數(shù)據(jù)庫(kù)
本文地址:http://www.5511xx.com/article/dhodpji.html


咨詢
建站咨詢
