java连接Oracle数据库

笔记:

方式一:采用JDBC-ODBC Bridge连接oracle数据库

try
  {
   Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
   Connection ct=DriverManager.getConnection("jdbc:odbc:XXXX","scott","orcl");
   Statement sm=ct.createStatement();
   ResultSet rs=sm.executeQuery("select * from emp");
   while(rs.next())
   {
    System.out.println("用户名: "+rs.getString(2));
   }
  
  }
  catch(Exception e)
  {
   e.printStackTrace();
  }

方式二:jdbc的thin方式

try
  {
   Class.forName("oracle.jdbc.driver.OracleDriver");
   Connection ct=DriverManager.getConnection("jdbc:oracle:thin:@127.0.0.1:1521:ORCL","scott","orcl");
   Statement sm=ct.createStatement();
   ResultSet rs=sm.executeQuery("select * from emp");
   while(rs.next())
   {
    System.out.println("用户名: "+rs.getString(2));
   }
  
  }
  catch(Exception e)
  {
   e.printStackTrace();
  }

posted on 2012-02-10 20:15  IT@民工  阅读(139)  评论(0编辑  收藏  举报

导航