道招

java jdbc连接oracle数据库

如果您发现本文排版有问题,可以先点击下面的链接切换至老版进行查看!!!

java jdbc连接oracle数据库

本人用的是MyEclipse10 ,JAVA用的是1.7,oracle用的是database 11g [code lang="java"] import java.sql.*; public class TestJDBC { public static void main(String[] args) { Connection conn = null; Statement stmt = null; ResultSet rs = null; try { Class.forName("oracle.jdbc.driver.OracleDriver"); //new oracle.jdbc.driver.OracleDriver(); conn = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:orcl","scott","tiger"); stmt = conn.createStatement(); rs = stmt.executeQuery("select * from dept"); while(rs.next()) { System.out.print(rs.getString("deptno") + " "); System.out.println(rs.getString("dname")); } } catch (ClassNotFoundException e) { e.printStackTrace(); } catch (SQLException e) { e.printStackTrace(); } finally { try { if(rs != null) { rs.close(); rs = null; } if(stmt != null) { stmt.close(); stmt = null; } if(conn != null) { conn.close(); conn = null; } } catch (SQLException e) { e.printStackTrace(); } } } } [/code]
更新时间:
上一篇:下一篇:

相关文章

关注道招网公众帐号