java连接Oracle详解
2017-09-18 15:23
225 查看
package demo.utils; import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; public class JDBCUtils { private static String driver = "oracle.jdbc.OracleDriver"; private static String url = "jdbc:oracle:thin:@172.0.0.1:1521:orcl"; //172.0.0.1是你的数据库所在ip地址,不知道的自己百度 //name和password是数据库的用户名和密码 private static String name = "scott"; private static String password = "scott"; //注册数据库的驱动 static{ try { Class.forName(driver); //DriverManager.registerDriver(driver); } catch (ClassNotFoundException e) { throw new ExceptionInInitializerError(e); } } //获取数据库的连接 public static Connection getConnection(){ try { return DriverManager.getConnection(url, name, password); } catch (SQLException e) { e.printStackTrace(); } return null; } //释放数据库的资源 public static void release(Connection conn,Statement st,ResultSet rs){ if(rs !=null){ try { rs.close(); } catch (SQLException e) { e.printStackTrace(); }finally{ rs = null; } } if(st != null){ try { st.close(); } catch (SQLException e) { e.printStackTrace(); }finally{ st = null; } } if(conn != null){ try { conn.close(); } catch (SQLException e) { e.printStackTrace(); }finally{ conn = null; } } } }
具体代码和jar包下载地址http://pan.baidu.com/s/1b3QqVO
相关文章推荐
- Java连接oracle的两种方式详解
- JAVA JDBC 连接Oracle方式详解
- java中连接oracle
- 如何在Oracle中使用Java存储过程 (详解)
- java weblogic oracle相关连接基础知识收集
- linux平台java连接oracle 10g
- Java 与 Oracle 数据库的连接
- Java连接数据库(mysql,sqlsever,Oracle,access)的调用函数!
- java 连接SQL,Oracle,access,excel表的语句
- Java连接Mysql,SQL Server, Access,Oracle
- 如何连接oracle,mysql, SQL Server数据库(Java版)
- JAVA连接各种数据库(mysql,sql server,oracle,db2)
- Java连接Mysql,SQL Server, Access,Oracle
- Java连接oracle测试代码
- 如何在Oracle中使用Java存储过程 (详解)
- JAVA 连接 oracle
- java连接oracle,取io文件内容,子串替换(原作)!
- java连接操作Oracle出现的问题及解决方法
- JAVA连接ORACLE
- java中连接oracle