Unable to connect to oracle database using jdbc thin drivers

I am trying to connect to Oracle 10 XE database using Oracle thin drivers but I’m unable to achieve this. I even added the drivers to my classpath during compilation.

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Properties;

public class Connectivity {
    public static void main(String args[]) throws SQLException {
        String url = "jdbc:oracle:thin:@localhost:1521:XE";
        Properties props = new Properties();

        props.setProperty("user", "SYSTEM");
        props.setProperty("password", "iiita");

        try {
            Class.forName ("oracle.jdbc.driver.OracleDriver");
        } catch (ClassNotFoundException e) {
            System.out.println(e.getMessage());
        }
        Connection conn = DriverManager.getConnection(url,props);
        String sql ="select sysdate as current_day from dual";

        PreparedStatement preStatement = conn.prepareStatement(sql);

        ResultSet result = preStatement.executeQuery();

        while(result.next()){
            System.out.println("Current Date from Oracle : " +  result.getString("current_day"));
        }

        System.out.println("done");

    }
}

This code gives the following error during running

Exception in thread "main" java.sql.SQLException: No suitable driver found for jdbc:oracle:thin:@localhost:1521/XE
    at java.sql.DriverManager.getConnection(DriverManager.java:644)
    at java.sql.DriverManager.getConnection(DriverManager.java:202)
    at Connectivity.main(Connectivity.java:16)

How to install Oracle thin jdbc drivers on ubuntu

I have downloaded the .jar files of drivers from this link http://www.oracle.com/technetwork/database/enterprise-edition/jdbc-10201-088211.html But now, I’m not sure what to do with these .jar files.

JDBC Connect String for Oracle OID Using OCI Driver

I know how to connect to oracle using OID and the thin client jdbc driver: jdbc:oracle:thin:@ldap://server:port/xyz,cn=abc,dc=def,dc=ghi I cannot, though, connect using jdbc, oci and oid. Oracle keeps



How to create a database in Oracle using JDBC?

I want to create a new database on an Oracle server via JDBC. I cannot seem to connect to the database without providing an SID: using a URL like jdbc:oracle:thin:@//[IP]:1521 results in an error of

Database connection encryption and integrity with ColdFusion and Oracle thin client

As ColdFusion datasource we are using the Oracle thin client to connect with the database. So, basically we are using a JDBC URL such as jdbc:oracle:thin:@… and as Driver Class oracle.jdbc.OracleDri

JDBC Connection to Oracle database using TLS Certificate

I am trying to write a connection class in java to connect to oracle database using jdbc drivers but I want to secure the parameters like jdbcurl/username/password which is used to connect to the orac

Cannot establish a connection to jdbc:oracle:thin:@localhost:1521:XXX using oracle.jdbc.OracleDriver

This is the error message I get when I try to connect my local DataBase to the NetBeans IDE. I hardly have any experience using netbeans either, the URL I used to connect using Oracle thin is: jdbc:or

Not able to connect to oracle database using JDBC if password is having special characters

I am trying to connect to oracle database using JDBC. following is the code:: public class OraclePwdTest { static{ try { Class.forName(oracle.jdbc.OracleDriver); } catch (ClassNotFoundException e)

Coldfusion oracle jdbc Macromedia vs Thin

I have done a lot of searching about this, but cannot seem to get a clear list of the limitations of Macromedia versus thin Oracle JDBC drivers, because they have big differences that I’m not understa

Unable to connect to oracle database from groovy

Hi i am unable to connect to oracle database in groovy . I have used the following code in groovy console but getting the following compilation error unable to resolve class oracle.jdbc.driver.Oracle

Connect to Oracle using Slick

I am trying to connect to Oracle using Slick. I got the slick-extensions_2.10-1.0.0.jar. Added the line below in Scala Database.forURL(jdbc:oracle:thin:@myhost:myport:dbalias, myid, mypwd, null,

Answers

Add this line before your call to getConnection(url, props)

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

It isn’t enough to have the jars on your classpath unless they are jdbc driver > 4.0 version. You have to actually register the driver with the DriverManager.

Change jdbc:oracle:thin:@localhost:1521:XE to jdbc:oracle:thin:@//localhost:1521:XE. I believe this is the new syntax.

Compile as

javac -classpath /<your_path>/ojdbc6.jar Connectivity.java

Run as

java Connectivity

You forgot to specify the ojdbc14 classpath when running the main class:

For Windows: java -cp .;<path>/ojdbc14.jar Connectivity

On Linux: java -cp .:<path>/ojdbc14.jar Connectivity

P.S. You don’t need ojdbc14.jar on your classpath to compile the main class. It’s a runtime dependency.