0

I have installed oracle 11g into my system. I have created my own data source using ODBC Data Sources in control panel. Details are given as shown in the image below :

enter image description here

I was trying to trying to access this data source through my java code :

JdbcType1Test.java

package connectionTests;

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

public class JdbcType1Test {

    public static void main(String[] args)throws ClassNotFoundException,SQLException {

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

        Connection con = DriverManager.getConnection("jdbc:odbc:nithin_ds","system","manager");

        System.out.println(con);

    }

}

After executing the above program I am getting errors like this:

Exception in thread "main" java.sql.SQLException: No suitable driver found for jdbc:odbc:nithin_ds
    at java.sql.DriverManager.getConnection(Unknown Source)
    at java.sql.DriverManager.getConnection(Unknown Source)
    at connectionTests.JdbcType1Test.main(JdbcType1Test.java:13)
Nithin
  • 748
  • 1
  • 10
  • 27
  • try `Class.forName("oracle.jdbc.driver.OracleDriver");` – Youcef LAIDANI Dec 24 '17 at 12:28
  • i have changed , still getting same exception – Nithin Dec 24 '17 at 12:28
  • 1
    Java no longer has support for ODBC (and that support was always pretty buggy). If you want to connect to Oracle, you need to use the Oracle JDBC driver **and** the correct JDBC url for Oracle. Your current URL isn't valid. – Mark Rotteveel Dec 24 '17 at 12:29
  • read this https://www.mkyong.com/jdbc/connect-to-oracle-db-via-jdbc-driver-java/ – Youcef LAIDANI Dec 24 '17 at 12:29
  • Since I am working in eclipse, the project where I have this code has ojdbc14.jar in its classpath ... i have used `Class.forName("oracle.jdbc.driver.OracleDriver");` in other codes also ... they are working fine – Nithin Dec 24 '17 at 12:33
  • i know there is mistake with url and that is due to **nithin_ds** data source. so in control panel i have cross checked by clicking **test connection** . As a response i got **connection successful** message. Still I cannot make out what is wrong with my url – Nithin Dec 24 '17 at 12:44
  • Valid connection URL for JDBC for Oracle looks like this: `jdbc:oracle:thin:@HOST:PORT/SERVICE_NAME` or `jdbc:oracle:thin:@HOST:PORT:SID` – Ivan Dec 25 '17 at 02:55
  • Yea thats true but I was following a video tutorial which was using the url pattern mentioned in the problem ... it was working fine. – Nithin Dec 25 '17 at 03:52

0 Answers0