Solved

Import oracle cannot be resolved

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

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
ejb mdb examples 1 39
Bot application - advice 3 81
convert Systemjs to Webpack 3 126
Hibernate Inheritance Strategy for Abstract Base class and two concrete classes 3 39
If you haven’t already, I encourage you to read the first article (http://www.experts-exchange.com/articles/18680/An-Introduction-to-R-Programming-and-R-Studio.html) in my series to gain a basic foundation of R and R Studio.  You will also find the …
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

739 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