Solved

Import oracle cannot be resolved

Posted on 2012-03-28
5
1,765 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
Suggested Courses

627 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