首页 > 代码库 > java连接oracle

java连接oracle

//使用java操作oracle数据库的例子
//文件名:testora.java
import java.sql.*;
public class testora {
    public static void main(String args[]) {
        try {
            Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); 
            Connection conn = DriverManager.getConnection("jdbc:odbc:myorc80","username","password");
            Statement sm=conn.createStatement();
            ResultSet rs=sm.executeQuery("select * from emp");
            
            System.out.println("编号"+"  "+"姓名"+"  "+"职位"+"  "+"领导编号"
                +"  "+"雇佣日期"+"  "+"工资"+"  "+"奖金"+"  "+"部门编号");
            while(rs.next()) {
                System.out.print(rs.getString(1)+"  ");
                System.out.print(rs.getString(2)+"  ");
                System.out.print(rs.getString(3)+"  ");
                System.out.print(rs.getString(4)+"  ");
                System.out.print(rs.getString(5)+"  ");
                System.out.print(rs.getString(6)+"  ");
                System.out.print(rs.getString(7)+"  ");
                System.out.println(rs.getString(8));
            }
            conn.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

java连接oracle