-1

下面是我的 JDBC Oracle Connectivity 的简单程序。请查看并告诉我为什么我可能会收到驱动程序未加载的错误。我已经放入odbc14.jar图书馆。

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package databaseconnect;

/**
 *
 * @author compaq
 */
import java.sql.*;

public class Education1 {

    public static void main(String[] args) {

        try{
            Class.forName("oracle:jdbc:driver:OracleDriver");
        }catch( Exception e ) {
      System.out.println("Failed to load Oracle driver.");
        }
try{
            Connection con=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe","system","system");
            Statement stmt=con.createStatement();
            stmt.executeUpdate("insert into Education(name,rollno) VALUES ('alankrit',1000)");
            System.out.println("Data inserted");
            con.close();


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

    }

}
4

2 回答 2

1

您需要如下传递类名,将 : 替换为 .

 Class.forName("oracle.jdbc.driver.OracleDriver");

具有字符串格式的完整包名称的驱动程序实现类。

这样反射api可以在运行时加载这个类

于 2013-04-02T12:26:35.710 回答
0

代替

Class.forName("oracle:jdbc:driver:OracleDriver");

利用

Class.forName("oracle.jdbc.OracleDriver");

并确保您odbc14.jar的类路径中有文件。

于 2013-04-02T12:34:19.097 回答