java连接oracle范例

 

需要引用:ojdbc6.jar

java连接oracle范例
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;
            }
        }
    }
}
java连接oracle范例

java连接oracle范例

上一篇:SQL存储过程知识总结


下一篇:继承的实现