0

I tried to connect my Java application to my Oracle database and I got this exception

java.lang.ClassNotFoundException: oracle.jdbc.driver.OracleDriver at java.net.URLClassLoader$1.run(Unknown Source) at java.net.URLClassLoader$1.run(Unknown Source) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) at java.lang.Class.forName0(Native Method) at java.lang.Class.forName(Unknown Source) at Com.getConnection(Com.java:11) at Main.main(Main.java:7)

and there is my code:

import java.sql.Connection;
import java.sql.DriverManager;

public class Com {

    public static Connection getConnection(){
        Connection conn = null;
        try{
            Class.forName("oracle.jdbc.driver.OracleDriver");
            conn = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1522:orcl", "SH12", "121212");

        }catch (Exception e) {
            e.printStackTrace();
        }
        return conn;
    }


    public static void closeConnection(Connection conn){
        try{
            if(conn != null){
                if(!conn.isClosed()){
                    conn.close();
                }
            }
        }catch (Exception e) {
            e.printStackTrace();
        }
    }

}
  • 1
    Is you database up and running (ps -ef | grep ora)? If not, this is a programming question. I'm going to have to vote to close unless you can show that this database/dba related. – Vérace Mar 24 '16 at 14:44
  • Your ODBC library isn't properly set up or your classpath is wrong, this is a programming question – Tom V Mar 24 '16 at 15:02
  • 1
    Do you have a `jar` file with the correct drivers on your class path? – brso05 Mar 24 '16 at 15:06
  • and just as an aside, connection requests to 'localhost' will never leave the requesting system. And that is not an Oracle issue, it is fundamental networking on which oracle relies. Think about the implications of coding your app in such a way that a connection request will never leave the client machine. – EdStevens Mar 24 '16 at 22:03
  • i've find a solution on this youtube link : https://www.youtube.com/watch?v=02rdKib1u4A – mehdi khamassi Mar 25 '16 at 08:03

0 Answers0