jdbc连接oracle
2018-10-22 17:38
92 查看
[code]public static void main(String[] args) { String driver = "oracle.jdbc.OracleDriver"; //驱动标识符 String url = "jdbc:oracle:thin:@localhost:1521:orcl"; //链接字符串 // url ="jdbc:oracle:thin:@10.0.30.64:1521:orcl"; // 连接远程的数据库可以这么写 String user = "scott"; //数据库的用户名 String password = "tiger"; //数据库的密码 Connection con = null; PreparedStatement pstm = null; ResultSet rs = null; boolean flag = false; try { Class.forName(driver); con = DriverManager.getConnection(url,user, password); String sql = "select * from emp"; pstm =con.prepareStatement(sql); rs = pstm.executeQuery(); while(rs.next()) { int empno = rs.getInt("empno"); String ename =rs.getString("ename"); double sal = rs.getDouble("sal"); Date hiredate =rs.getDate("hiredate"); int deptno = rs.getInt(("deptno")); System.out.println(empno +"\t"+ ename +"\t"+ sal +"\t"+ hiredate +"\t"+ deptno); } flag = true; } catch(ClassNotFoundException e) { e.printStackTrace(); } catch(SQLException e) { e.printStackTrace(); } finally { if(rs != null) { try { rs.close(); } catch (SQLException e) { e.printStackTrace(); } } // 关闭执行通道 if(pstm !=null) { try { pstm.close(); } catch (SQLException e) { e.printStackTrace(); } } // 关闭连接通道 try { if(con != null &&(!con.isClosed())) { try { con.close(); } catch (SQLException e) { e.printStackTrace(); } } } catch (SQLException e) { e.printStackTrace(); } } if(flag) { System.out.println("执行成功!"); } else { System.out.println("执行失败!"); } }
阅读更多
相关文章推荐
- JDBC(与Oracle的连接)(转)
- JDBC纯驱动方式连接Oracle
- JDBC连接oracle,修改数据库图片路径
- jdbc 连接oracle 并实现查询功能
- JDBC连接Oracle的简单例子
- 基于Oracle的JDBC连接教程
- JDBC连接ORACLE的三种URL格式
- JDBC使用TNS连接多节点Oracle
- Oracle JDBC连接服务名、SID和tnsnames.ora配置的多种方式
- mysql、ms sql、oracle3中连接jdbc的方式 2009-11-12 04:10 486人阅读 评论(1) 收藏
- Oracle 12c JDBC 连接
- jdbc连接Oracle
- [备忘] java jdbc odbc 连接oracle
- JDBC连接ORACLE常见错误汇总
- oracle 12c jdbc连接pdb报错的问题
- powerdesigner jdbc 连接 oracle
- JDBC连接ORACLE
- oracle--jdbc数据库连接
- Oracle-JDBC连接
- oracle的jdbc连接方式:oci和thin