Solved

Import oracle cannot be resolved

Posted on 2012-03-28
5
1,491 Views
Last Modified: 2012-04-09
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!
0
Comment
Question by:neoarwin
  • 4
5 Comments
 
LVL 47

Expert Comment

by:for_yan
ID: 37776990
Is DatabaseError.java - your custom code ?
If it is, what is exactly line 125 ?
0
 
LVL 47

Expert Comment

by:for_yan
ID: 37777023
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
0
 
LVL 47

Expert Comment

by:for_yan
ID: 37777113
This is the correct format of the URL for Orcale:

String URL = "jdbc:oracle:thin:@hostname.com:1521:dbname";
0
 
LVL 47

Accepted Solution

by:
for_yan earned 400 total points
ID: 37777120
So use this:

String URL = "jdbc:oracle:thin:@134.65.171.119:1521:sirdx2;

or if it is on loacla machine:


String URL = "jdbc:oracle:thin:@localhost:1521:sirdx2;
0
 

Author Closing Comment

by:neoarwin
ID: 37822570
thanks
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Suggested Solutions

Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The purpose of this article is to demonstrate how we can use conditional statements using Python.
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now