Alaska Cowboy
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-dim ension:152 1: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.Or acleDriver ");
//from http://www.orafaq.com/faqjdbc.htm#THIN
conn = DriverManager.getConnectio n ("jdbc:oracle:thin:@dell-d imension:1 521:XE","b peck","don na100"); <----- 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.ge tString(1) );
}
stmt.close();
System.out.println("This is the end of the CD application.");
} catch (Exception e) {
System.out.println(e.getMe ssage());
}
}
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.ge tString(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.getMe ssage());
}
}
}
(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-dim
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
//from http://www.orafaq.com/faqjdbc.htm#THIN
conn = DriverManager.getConnectio
Statement stmt = conn.createStatement();
ResultSet rset = stmt.executeQuery("select 'x' from sys.dual");
while (rset.next()) {
System.out.println(rset.ge
}
stmt.close();
System.out.println("This is the end of the CD application.");
} catch (Exception e) {
System.out.println(e.getMe
}
}
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.ge
}
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.getMe
}
}
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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.getConnectio n ("jdbc:oracle:thin:bpeck/d onna100@de ll-dimensi on: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.OracleDat aSource;
class JDBCVersion
{
public static void main (String args[]) throws SQLException
{
OracleDataSource ods = new OracleDataSource();
ods.setURL("jdbc:oracle:th in:hr/hr@l ocalhost:1 521/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());
}
}
--> "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.getConnectio
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.OracleDat
class JDBCVersion
{
public static void main (String args[]) throws SQLException
{
OracleDataSource ods = new OracleDataSource();
ods.setURL("jdbc:oracle:th
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
Your tnsnames.ora file should help. See
http://e-docs.bea.com/wls/docs90/jdbc_drivers/oracle.html#1066766
http://e-docs.bea.com/wls/docs90/jdbc_drivers/oracle.html#1066766
ASKER
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.getConnectio n ("jdbc:oracle:thin:@DELL-D IMENSION:2 030:XE","b peck","don na100");
Maybe it can't handle the "dash" in Dell - Dimension . . . th
conn = DriverManager.getConnectio
Nothing wrong with dash. Look in tnsnames.ora as i mentioned
ASKER
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 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
Think it could do, yes. Not 100% certain
ASKER
Ok, I'm good now. Thanks - my first foray into EE-Java.
I'm sure I'll be back.
I'm sure I'll be back.
:-)
ASKER