Link to home
Start Free TrialLog in
Avatar of Alaska Cowboy
Alaska CowboyFlag for United States of America

asked on

Can't connect to Oracle with Eclipse

I'm trying to connect to Oracle using Eclipse.

(I am learning Java; I am proficient in Oracle / Access)

The same code works at work so I thought I could get it going at home.

Oracle is all set at home - I can connect via Pl * Sql Developer as well as through Access.

One thing I did (that I also did at work) is add to my Java build path "ojdbc14.jar"

When I de-bug, it says "No suitable driver found for jdbc:oracle:thin:@dell-dimension:1521:XE"

Here's my code:

/**
 * @author bpeck
 * July 20, 2007
 *
 * The CD Catalog Application retrieves data from an Oracle d.b.
 *
 */

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
      
public class ArtistDAO {

      private Connection conn = null;

      public ArtistDAO() {
            System.out.println("Start of Artist DAO");
            try {
            
            System.out.println("This is the beginning of the CD application.");
//            Class.forName("oracle.jdbc.driver.OracleDriver");
                         
            //from http://www.orafaq.com/faqjdbc.htm#THIN
            conn = DriverManager.getConnection ("jdbc:oracle:thin:@dell-dimension:1521:XE","bpeck","donna100"); <----- this statement doesn't work (the server is definitely lower-case "dell-dimension"
            
            Statement stmt = conn.createStatement();
            ResultSet rset = stmt.executeQuery("select 'x' from sys.dual");
            while (rset.next()) {
                  System.out.println(rset.getString(1));
            }
            stmt.close();                  
                              
            System.out.println("This is the end of the CD application.");
            } catch (Exception e) {
                  System.out.println(e.getMessage());
            }
      }

      public void findArtistID() throws Exception {
            Statement stmt = conn.createStatement();
            ResultSet rset = stmt.executeQuery("select artist_name from artists");
            while (rset.next()) {
                  System.out.println(rset.getString(1));
            }
            stmt.close();                  
                              
            System.out.println("This is the end of the CD application.");
            
      }

      public static void main(String[] args) {
            try {
                  ArtistDAO artistDAO = new ArtistDAO();
                  artistDAO.findArtistID();
            } catch (Exception e) {
                  System.out.println(e.getMessage());
            }
      }
}
Avatar of Alaska Cowboy
Alaska Cowboy
Flag of United States of America image

ASKER

I checked the port in the Pl * Sql Developer profile, and it said port 2030. So I changed that but got the same result.
ASKER CERTIFIED SOLUTION
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland 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
ok, i'm getting closer, now I got

--> "Io exception: The Network Adapter could not establish the connection".

This is what happened at work, and when we changed the server to all upper-case, then we connected.

(I will be out until about 4pm today New York time), but thanks for your help.

For this question, I am at home, running Eclipse, Oracle Client-XE, Oracle Server-XE all on the machine dell-dimension, which is definitely lower-case.

I found this site, which is exactly what I am doing, but still no luck.
http://download.oracle.com/docs/cd/B25329_01/doc/appdev.102/b25320/getstart.htm#CIAIBADE

So, based on the above link, I changed my connection to
            conn = DriverManager.getConnection ("jdbc:oracle:thin:bpeck/donna100@dell-dimension:2030/XE");

but this results in 10 compile errors, such as
   - Syntax error, insert ) to complete expression
   - Syntax error, insert "AssignmentOperator Experssion" to complete Expression


Here's the code sample

import java.sql.*;
import oracle.jdbc.*;
import oracle.jdbc.pool.OracleDataSource;

class JDBCVersion
{
  public static void main (String args[]) throws SQLException
  {
    OracleDataSource ods = new OracleDataSource();
    ods.setURL("jdbc:oracle:thin:hr/hr@localhost:1521/XE");
    Connection conn = ods.getConnection();

    // Create Oracle DatabaseMetaData object
    DatabaseMetaData meta = conn.getMetaData();

    // gets driver info:
    System.out.println("JDBC driver version is " + meta.getDriverVersion());
  }
}
I wouldn't use anything other than generic JDBC
Just to be sure, I tried DELL-DIMENSION, using my original connection string.

Maybe it can't handle the "dash" in Dell - Dimension . . . th

            conn = DriverManager.getConnection ("jdbc:oracle:thin:@DELL-DIMENSION:2030:XE","bpeck","donna100");
Nothing wrong with dash. Look in tnsnames.ora as i mentioned
oops - terribly sorry - I'm now connected . . . .

I changed the port to 1521 and am now connected . . .

(I don't think Oracle XE uses tnsnames, does it?)

2030 was the port for Pl * Sql Developer, so I thought that's what I needed for this.

getting started with Java so on shaky ground . . .

thanks for the tips
>>(I don't think Oracle XE uses tnsnames, does it?)

Think it could do, yes. Not 100% certain
Ok, I'm good now. Thanks - my first foray into EE-Java.

I'm sure I'll be back.
:-)