RE: Trying to connect to an Oracle db through Java, but I got this message??
"David, Romeo B. (Govt)" <[email protected]>
| Newsgroups | gmane.comp.db.oracle.devel |
|---|---|
| Message-ID | <LYRIS-1796914-819979-2003.01.03-16.19.13--gcdod-oracle#[email protected]> |
Try changing the String sourceURL=new String("jdbc:odbc:aldo"); to
String sourceURL=new String("jdbc:odbc:aldo:");
or try to change the way you load your driver. i am not sure if the
"Class.forName()" method works in your machine. it is said that that method
works only for JDK-compliant Java Virtual Machines, not on Microsoft Java
Virtual Machines.Try using the DriverManager.registerDriver() method.
-----Original Message-----
From: aldo [mailto:[email protected]]
Sent: Friday, December 27, 2002 6:59 PM
To: Oracle
Subject: [oracle] Trying to connect to an Oracle db through Java, but I
got this message??
Hi, I tried to connect to an Oracle database whose SID is called Aldo on
my local machine called (server) on a WIN 2000 plattaform.
I have set the ODBC driver under Win 2000 as described on the paragraph:
Setting up a Database page 1015 of Beginning Java2 jdk1.3 on System DSN:
the name source data is aldo, the user name: SYSTEM, the Server: server,
but when I run the MakingAStatement.java under JBuilder6 I got this
message or error, why???:
C:\JBuilder6\jdk1.3.1\bin\javaw -classpath "C:\JBuilder6
\samples\Welcome\classes;C:\JBuilder6\jdk1.3.1
\demo\jfc\Java2D\Java2Demo.jar;C:\JBuilder6\jdk1.3.1
\jre\lib\i18n.jar;C:\JBuilder6\jdk1.3.1\jre\lib\jaws.jar;C:\JBuilder6
\jdk1.3.1\jre\lib\rt.jar;C:\JBuilder6\jdk1.3.1
\jre\lib\sunrsasign.jar;C:\JBuilder6\jdk1.3.1\lib\dt.jar;C:\JBuilder6
\jdk1.3.1\lib\htmlconverter.jar;C:\JBuilder6\jdk1.3.1\lib\tools.jar"
MakingAStatement
java.sql.SQLException: [Microsoft][ODBC driver for Oracle][Oracle]ORA-
12514: TNS:listener could not resolve SERVICE_NAME given in connect
descriptor
the code of the java program whether you are interested in is:
import java.sql.*;
public class MakingAStatement
{
public static void main(String[]args)
{
//Load the driver
try
{
//Load the driver class
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
//This defines the data source for the driver
String sourceURL=new String("jdbc:odbc:aldo");
//Create connection through the DriveManager
Connection databaseConnection=
DriverManager.getConnection(sourceURL);
Statement statement=databaseConnection.createStatement();
ResultSet authorNames= statement.executeQuery
("SELECT lastname, firstname FROM authors");
// Output the resultset data
while(authorNames.next())
System.out.println(authorNames.getString("lastname")+" "+
authorNames.getString("firstname"));
}
catch(ClassNotFoundException cnfe)
{
System.err.println(cnfe);
}
catch(SQLException sqle);
{
System.err.println(sqle);
}
}
}
Thanks in advance
Aldo
---
Change your mail options at http://p2p.wrox.com/manager.asp or
to unsubscribe send a blank email to %%email.unsub%%.
---
Change your mail options at http://p2p.wrox.com/manager.asp or
to unsubscribe send a blank email to [email protected].