JDBC驱动程序文件放在哪里?

时间:2018-06-21 14:49:39

标签: oracle jdbc oracle11g

我正在尝试连接到oracle xe 11g服务器(11.2),并且在尝试运行程序时收到错误消息:

  

java.lang.ClassNotFoundException:oracle.jdbc.driver.OracleDriver

我已经安装了ojdbc7,并且它同时包含了connect.class和connect.java文件。我究竟做错了什么?抱歉,这是补救性的,是oracle的新功能。

 public static void main(String args[]){  
        try{  
        //step1 load the driver class  
        Class.forName("oracle.jdbc.driver.OracleDriver");



    //step2 create  the connection object  
    Connection con=DriverManager.getConnection(  
    "jdbc:oracle:thin:@localhost:1521:xe","system","oracle");  

    //step3 create the statement object  
    Statement stmt=con.createStatement();  

    //step4 execute query  
    ResultSet rs=stmt.executeQuery("select * from emp");  
    while(rs.next())  
    System.out.println(rs.getInt(1)+"  "+rs.getString(2)+"  "+rs.getString(3));  

    //step5 close the connection object  
    con.close();  

    }catch(Exception e){ System.out.println(e);}  

    }  

1 个答案:

答案 0 :(得分:0)

已解决。.我需要将驱动程序添加到构建路径中。

相关问题