ORACLE数据库JDBC连接
2015-09-18 16:30
375 查看
--建立驱动,使用SQL,通过传入 sql调用方法,获取结果集
public static ResultSet getResult(String sql){ <pre name="code" class="java"> Connection con = getConnection(); try{ Statement stmt = con.createStatement() ; ResultSet rs = stmt.executeQuery(sql) ; //con.close(); return rs; }catch(SQLException e){ // TODO Auto-generated catch block } return null; } private static Connection getConnection(){ try{ Properties p = new Properties(); InputStream in =null; String driver=""; String username=""; String password=""; String url=""; try{ in=new FileInputStream("WebContent/datasource.properties"); p.load(in); driver=p.getProperty("jdbc.driverClassName"); url=p.getProperty("jdbc.url"); username=p.getProperty("jdbc.username"); password=p.getProperty("jdbc.password"); System.out.println(driver); }catch(FileNotFoundException e){ // TODO Auto-generated catch block e.printStackTrace(); }catch(IOException e){ // TODO Auto-generated catch block e.printStackTrace(); } //加载oracle驱动 Class.forName(driver); Connection con = DriverManager.getConnection(url , username , password ) ; return con; }catch(ClassNotFoundException e){ System.out.println("找不到驱动程序类 ,加载驱动失败!"); e.printStackTrace() ; }catch(SQLException e){ // TODO Auto-generated catch block e.printStackTrace(); } return null; } 数据库配置文本内容datasource.properties <p>jdbc.driverClassName=oracle.jdbc.driver.OracleDriver url=jdbc:oracle:thin:@172.18.94.63/orcl username= password=
相关文章推荐
- 关于oracle 安装结束后的ORA-12560: TNS: 协议适配器错误的解决方法
- oracle某张表size暴涨问题分析处理
- Oracle 分页
- oracle回顾--视图、PL/SQL、游标
- sql:Oracle11g 表,视图,存储过程结构查询
- oracle 数据导入导出
- Oracle database 11.2.0.3.0 升级至 11.2.0.3.14
- Oracle with as (hint inline materialize)
- oracle数据库拷贝
- oracle学习之bulk collect用法
- Oracle中的索引详解
- Oracle存储过程的调试
- ORA-00257: oracle报archiver error的解决方法
- oracle回顾--基础篇(二)
- 删除oracle重复数据
- Java并发教程(Oracle官方资料)
- 【JAVA】 Java、JSP连接数据库方法类(MySQL、Oracle、SQLServer)
- Oracle create table as 的坑
- oracle经验
- oracle utf8字符集转gbk(转)