Routray
Routray

Reputation: 75

getting error as "SQL State: 08001 No suitable driver found for jdbc:oracle:thin:@128:23:44:01:12345:pppp_rr

Can some one suggest what wrong i am doing here:

Getting error message as "SQL State: 08001 No suitable driver found for jdbc:oracle:thin:@128:23:44:01:12345:pppp_rr Picked up JAVA_TOOL_OPTIONS: -Duser.home=C:\Users\123ert"

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

public class JDBCExample {

    public static void main(String[] args) {

        try (Connection conn = DriverManager.getConnection(
                "jdbc:oracle:thin:@128:23:44:01:12345:pppp_rr", "Test123", "********")) {

            if (conn != null) {
                System.out.println("Connected to the database!");
            } else {
                System.out.println("Failed to make connection!");
            }

        } catch (SQLException e) {
            System.err.format("SQL State: %s\n%s", e.getSQLState(), e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
        }

    }
}

enter image description here

Upvotes: 1

Views: 2667

Answers (1)

deHaar
deHaar

Reputation: 18558

I can't acutally test it with an Oracle database, but I know there must be a driver registered before a connection can be established. Check the following code, which is basically your code plus the driver registration.

public static void main(String args[]) throws Exception {
    // registration for the driver, it's needed, 
    // otherwise there will be "no suitable driver found"
    Class.forName("oracle.jdbc.driver.OracleDriver");

    try (Connection conn = DriverManager.getConnection(
            "jdbc:oracle:thin:@128:23:44:01:12345:pppp_rr", "Test123", "********")) {

        if (conn != null) {
            System.out.println("Connected to the database!");
        } else {
            System.out.println("Failed to make connection!");
        }

    } catch (SQLException e) {
        System.err.format("SQL State: %s\n%s", e.getSQLState(), e.getMessage());
    } catch (Exception e) {
        e.printStackTrace();
    }
}

Upvotes: 1

Related Questions