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());
            }
      }
}
LVL 1
Alaska CowboyAsked:
Who is Participating?
 
CEHJCommented:
>>//            Class.forName("oracle.jdbc.driver.OracleDriver");

Uncomment that line and let us know what happens
0
 
Alaska CowboyAuthor Commented:
I checked the port in the Pl * Sql Developer profile, and it said port 2030. So I changed that but got the same result.
0
 
Alaska CowboyAuthor Commented:
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());
  }
}
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

 
CEHJCommented:
I wouldn't use anything other than generic JDBC
0
 
CEHJCommented:
0
 
Alaska CowboyAuthor Commented:
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");
0
 
CEHJCommented:
Nothing wrong with dash. Look in tnsnames.ora as i mentioned
0
 
Alaska CowboyAuthor Commented:
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
0
 
CEHJCommented:
>>(I don't think Oracle XE uses tnsnames, does it?)

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

I'm sure I'll be back.
0
 
CEHJCommented:
:-)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.