ojdbc14 jar oracle 10g java java.lang.ClassNotFoundException

时间:2015-06-03 12:03:32

标签: java oracle jar oracle10g

你好,我遇到了以下错误

   java.lang.ClassNotFoundException: oracle.jdbc.pool.OracleConnectionPoolDataSource
Exception in thread "main" Message: No suitable driver found for jdbc:odbc:10.43.210.170:1521:radem
java.lang.NullPointerException
    at com.test.DBcnx.main(DBcnx.java:25)

我知道它之前已发布并且我检查了答案..试图将驱动程序(ojdbc14。jar)放在与该类相同的路径中,但仍然是相同的错误..我在java中的业余种类所以基本上我我不知道我在做什么或我应该做什么..我的代码如下:

    package com.test;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class DBcnx {

//connection
static   String url="jdbc:thin:oracle:10.43.210.170:1521:radem";
static         String user="USER1";
static         String pass="radem";
static         String driver="oracle.jdbc.pool.OracleConnectionPoolDataSource"; 


static Connection con;
static boolean isconnect ;

public static void main(String args[] ) throws SQLException  
{
    isconnect=Connect(url,user,pass,driver); 
    String select = "select * from dual"; 
    Statement stmt = con.createStatement();
    ResultSet result = stmt.executeQuery(select);
    while( result.next())
    {
     System.out.println(result.getString("TABLE_NAME"));
    }
    stmt.close();

}


public static boolean Connect(String url,String user,String pass, String driver)
    {


    try{
        try{
            Class.forName(driver);
            System.out.println("chargement driver");
             }catch(ClassNotFoundException e)
            {
                System.err.println("Chargement drivers echoue\n"+e); 
            }

            con = DriverManager.getConnection(url,user,pass);
            System.out.println("\nConnection a la base etablie");

        }
        catch(Exception evt)
        { 
                System.out.println("Message: "+ evt.getMessage()); ;
                return false; 
        }
        return true;
    }

}

任何帮助都是最受欢迎的..谢谢!

1 个答案:

答案 0 :(得分:0)

您的驱动程序类名称不正确。它应该是oracle.jdbc.OracleDriver。

您返回一个布尔标志以指示连接是否成功,但您忽略它。