需要引用:ojdbc6.jar
import java.sql.*; public class Main { static Connection conn; static Statement stat; static ResultSet rs; public static void main(String[]args){ try{ try { Class.forName("oracle.jdbc.driver.OracleDriver"); } catch (ClassNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } conn=DriverManager.getConnection("jdbc:oracle:thin:@192.168.140.110:1521/ora11g","ora","ora"); stat=conn.createStatement(); rs=stat.executeQuery("select * from all_users"); while(rs.next()){ System.out.println(rs.getString("username")); } }catch(SQLException e){ e.printStackTrace(); }finally{ if(rs!=null){ try { rs.close(); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } rs=null; } if(conn!=null){ try { conn.close(); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } conn=null; } } } }
原文:http://www.cnblogs.com/ola2010/p/3515736.html