java连接oracle范例
需要引用: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; } } } }
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。