Link to home
Start Free TrialLog in
Avatar of Aravindan GP
Aravindan GPFlag for United States of America

asked on

Import oracle cannot be resolved

Hi,

My java code :

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

import oracle.jdbc.OracleDriver;

public class ClassNameDemo {
    public ClassNameDemo() {
          System.out.println("Hello");
        System.setProperty("oracle.net.tns_admin","D:\\TNSNAMES.ORA");
        System.out.println("Hello");        
    }

    public void doit () throws SQLException {
          System.out.println("H");
        String usr = "MURUGANANTHAMM_CGZ_D2";
        String pwd = "MURUGANANTHAMM_CGZ_D2";
        System.out.println("He");
        //String url = "jdbc:oracle:thin:@//134.65.171.119:1521/sirdx2";
        String url = "jdbc:oracle:thin:@sirdx2";
        System.out.println("Hel");
        DriverManager.registerDriver(new OracleDriver());
        System.out.println("Hel1");
        Connection conn = DriverManager.getConnection(url,usr,pwd);
        System.out.println("Hell");
        String sql = "select sysdate from dual" ;
        System.out.println("Hello");
        Statement stmt = conn.createStatement();
        ResultSet rs = stmt.executeQuery(sql);
        while (rs.next())
            System.out.println("results: " + rs.getString(1));
        conn.close();
    }

    public static void main(String[] args){
          ClassNameDemo test = new ClassNameDemo();
        try {
            test.doit();
            System.out.println("Done..");
        }
        catch (SQLException e) {      
            e.printStackTrace();
        }
    }
}


output :

Hello
Hello
H
He
Hel
Hel1
java.sql.SQLException: Io exception: SO Exception was generated
      at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:125)
      at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:162)
      at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:274)
      at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:319)
      at oracle.jdbc.driver.PhysicalConnection.<init>(PhysicalConnection.java:344)
      at oracle.jdbc.driver.T4CConnection.<init>(T4CConnection.java:148)
      at oracle.jdbc.driver.T4CDriverExtension.getConnection(T4CDriverExtension.java:32)
      at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:545)
      at java.sql.DriverManager.getConnection(DriverManager.java:539)
      at java.sql.DriverManager.getConnection(DriverManager.java:189)
      at ClassNameDemo.doit(ClassNameDemo.java:26)
      at ClassNameDemo.main(ClassNameDemo.java:40)

Please help with this error!
Avatar of for_yan
for_yan
Flag of United States of America image

Is DatabaseError.java - your custom code ?
If it is, what is exactly line 125 ?
Discard my first question.But I think you need hist ad port in the URL, and you commented out the correct URL and left the url without host and port part
I understand that getCinnection method is giveing excepotiion because of it
This is the correct format of the URL for Orcale:

String URL = "jdbc:oracle:thin:@hostname.com:1521:dbname";
ASKER CERTIFIED SOLUTION
Avatar of for_yan
for_yan
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Aravindan GP

ASKER

thanks