最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
jdbc连接oracle数据库功能实例
时间:2022-06-29 09:29:11 编辑:袖梨 来源:一聚教程网
本文实例讲述了jdbc链接oracle数据库功能。分享给大家供大家参考,具体如下:
代码如下 | 复制代码 |
packagecom.sefvang.jdbc; importjava.sql.Connection; importjava.sql.DriverManager; importjava.sql.PreparedStatement; importjava.sql.ResultSet; importjava.sql.SQLException; publicclassDb_conn { privatestaticfinalString url ="jdbc:oracle:thin:@localhost:1521:orcl"; privatestaticfinalString name ="system"; privatestaticfinalString passwd ="sefvang"; privatestaticfinalString Db_driver ="oracle.jdbc.OracleDriver"; publicConnection getConnection() { Connection conn =null; try{ Class.forName(Db_driver); conn = DriverManager.getConnection(url, name, passwd); if(conn !=null) { System.out.println("success!!!"); } }catch(ClassNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); }catch(SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } returnconn; } publicvoidclose(Connection conn) { try{ if(conn !=null) { if(!conn.isClosed()) { conn.close(); } } }catch(SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } } publicstaticvoidmain(String[] args) { Db_conn conn=newDb_conn(); Connection con = conn.getConnection(); try{ PreparedStatement papt = con.prepareStatement("select tname from text where tid=1"); ResultSet rs = papt.executeQuery(); if(rs.next()) System.out.println(rs.getString(1)); }catch(SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } conn.close(con); } } |
相关文章
- 以闪亮之名店长体验流霞季怎么玩 缘溪临霞套装活动介绍 12-31
- 未定事件簿旧梦新生左然篇怎么玩 旧梦新生左然篇活动介绍 12-31
- 未定事件簿左然破浪远行怎么样 12-31
- 桃源深处有人家行医问诊怎么玩 12-31
- 恋与制作人跨年福利有哪些 恋与制作人跨年福利内容介绍 12-31
- 阴阳师协同对弈大乱斗怎么玩 阴阳师协同对弈大乱斗活动介绍 12-31