Java开发网 |
注册 |
登录 |
帮助 |
搜索 |
排行榜 |
发帖统计
|
您没有登录 |
» Java开发网 » Database/JDBC/SQL/JDO/Hibernate
打印话题 寄给朋友 订阅主题 |
话题被移动 | ||||
该话题已被移动 - dapan , 2003-07-22 15:43 如果您尚不清楚该话题被移动的原因,请参考论坛规则以及本版公告或者联系本版版主。 |
作者 | Re:jsp+weblogic连接oracle数据库的4种方法 [Re:li_chuansong] |
li_chuansong
发贴: 55 积分: 21 |
于 2003-07-23 08:54
2.采用weblogic的jdbc连接oracle // 建立数据库的连接 // package com.yourCompany.yourApp; package db_beans; import javax.sql.DataSource; import javax.naming.*; import java.lang.*; import java.sql.*; import java.io.*; import java.util.*; public class connect_db{ public Connection con = null; public ResultSet ret=null; public Statement stmt=null; //此连接为采用weblogic的jdbc直连接 public connect_db(){ try{ Properties props = new Properties(); props.put("user","cygs"); props.put("password","cygs"); props.put("server","study"); try{ Driver myDriver = (Driver) Class.forName("weblogic.jdbc.oci.Driver").newInstance(); con = myDriver.connect("jdbc:weblogic:oracle", props); }catch(Exception e){ System.out.println(e.getMessage()+e.toString()); } }catch(Exception ex){ ex.printStackTrace(); System.out.print(ex.toString()); return; } } //执行select语句,并返回结果集 public ResultSet execsql(String sql){ try { stmt=con.createStatement(); ret = stmt.executeQuery(sql); }catch(Exception e){ e.printStackTrace(); System.out.println(e.toString()); } return ret; } //执行insert,update,delete,ddl等,返回结果数或0 public int execupdate(String sql){ int recount=0; try { stmt=con.createStatement(); recount = stmt.executeUpdate(sql); }catch(Exception e){ e.printStackTrace(); System.out.println(e.toString()); } return recount; } //关闭打开的内容 public void closecon(){ try{ if (ret != null){ ret.close(); } if (stmt != null){ stmt.close(); } if (con != null){ con.close(); } }catch(Exception ex){ ex.printStackTrace(); } } } 3.采用weblogic的连接池jdbc用oracle thin // 建立数据库的连接 // package com.yourCompany.yourApp; package db_beans; import javax.sql.DataSource; import javax.naming.*; import java.lang.*; import java.sql.*; import java.io.*; import java.util.*; public class connect_pool_oracle{ public Connection con = null; public ResultSet ret=null; public Statement stmt=null; //此连接为采用weblogic的jdbc直连接 public connect_pool_oracle(){ try{ Properties props = new Properties(); props.put("connectionPoolID", "WebLogicOraclePool"); try{ Driver myDriver = (Driver)Class.forName("weblogic.jdbc.pool.Driver").newInstance(); con =myDriver.connect("jdbc:weblogic:pool", props); }catch(Exception e){ System.out.println(e.getMessage()+e.toString()); } }catch(Exception ex){ ex.printStackTrace(); System.out.print(ex.toString()); return; } } //执行select语句,并返回结果集 public ResultSet execsql(String sql){ try { stmt=con.createStatement(); ret = stmt.executeQuery(sql); }catch(Exception e){ e.printStackTrace(); System.out.println(e.toString()); } return ret; } //执行insert,update,delete,ddl等,返回结果数或0 public int execupdate(String sql){ int recount=0; try { stmt=con.createStatement(); recount = stmt.executeUpdate(sql); }catch(Exception e){ e.printStackTrace(); System.out.println(e.toString()); } return recount; } //关闭打开的内容 public void closecon(){ try{ if (ret != null){ ret.close(); } if (stmt != null){ stmt.close(); } if (con != null){ con.close(); } }catch(Exception ex){ ex.printStackTrace(); } } } 4.采用weblogic的连接池用weblogic的jdbc // 建立数据库的连接 // package com.yourCompany.yourApp; package db_beans; import javax.sql.DataSource; import javax.naming.*; import java.lang.*; import java.sql.*; import java.io.*; import java.util.*; public class connect_db_pool{ public Connection con = null; public ResultSet ret=null; public Statement stmt=null; //此连接为采用weblogic的jdbc直连接 public connect_db_pool(){ try{ Properties props = new Properties(); props.put("connectionPoolID", "WebLogicPool"); try{ Driver myDriver = (Driver)Class.forName("weblogic.jdbc.pool.Driver").newInstance(); //Driver myDriver = (Driver) Class.forName("weblogic.jdbc.oci.Driver").newInstance(); //con = myDriver.connect("jdbc:weblogic:oracle", props); con =myDriver.connect("jdbc:weblogic:pool", props); }catch(Exception e){ System.out.println(e.getMessage()+e.toString()); } }catch(Exception ex){ ex.printStackTrace(); System.out.print(ex.toString()); return; } } //执行select语句,并返回结果集 public ResultSet execsql(String sql){ try { stmt=con.createStatement(); ret = stmt.executeQuery(sql); }catch(Exception e){ e.printStackTrace(); System.out.println(e.toString()); } return ret; } //执行insert,update,delete,ddl等,返回结果数或0 public int execupdate(String sql){ int recount=0; try { stmt=con.createStatement(); recount = stmt.executeUpdate(sql); }catch(Exception e){ e.printStackTrace(); System.out.println(e.toString()); } return recount; } //关闭打开的内容 public void closecon(){ try{ if (ret != null){ ret.close(); } if (stmt != null){ stmt.close(); } if (con != null){ con.close(); } }catch(Exception ex){ ex.printStackTrace(); } } }
why edited on 2003-07-23 09:07
请求JAVA学习方向????? |
话题树型展开 |
人气 | 标题 | 作者 | 字数 | 发贴时间 |
12811 | [精华] jsp+weblogic连接oracle数据库的几种方法 | li_chuansong | 2045 | 2003-07-22 12:52 |
8971 | Re:jsp+weblogic连接oracle数据库的4种方法 | li_chuansong | 4859 | 2003-07-23 08:54 |
已读帖子 新的帖子 被删除的帖子 |
Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1 客服电话 18559299278 客服信箱 714923@qq.com 客服QQ 714923 |