Solved

Import oracle cannot be resolved

Posted on 2012-03-28
5
1,642 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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Bartender Integration Builder 3 62
Problem to refer to value 8 78
hashmap order 17 40
Setup GlassFish 4 34
This article will show, step by step, how to integrate R code into a R Sweave document
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.

685 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