Re: Trying to connect to an Oracle db through Java, but I got this message??

Roque Daudt <[email protected]>
Newsgroups gmane.comp.db.oracle.devel
Message-ID <LYRIS-1796914-819567-2003.01.03-05.54.46--gcdod-oracle#[email protected]>
I am not an expert in Java but it looks to me that you are making a
mistake when building the URL. Take a look on what can be found at
http://java.sun.com/j2se/1.3/docs/guide/jdbc/getstart/bridge.doc.html

*****
The Bridge driver uses the odbc subprotocol. URLs for this subprotocol
are of the form: 

    jdbc:odbc:<data-source-name>[;<attribute-name>=<attribute-value>]*

For example: 

    jdbc:odbc:sybase
    jdbc:odbc:mydb;UID=me;PWD=secret
    jdbc:odbc:ora123;Cachesize=300
*****

As you can see, you need to write the Data Source Name (DSN) in the
third part of the URL instead of the Oracle service name.

Try to go by steps. First, make sure that the you have created one DSN
with an ODBC driver to your datasource and that it is possible to
establish an ODBC connection to it. You can test it with any ODBC
client (MS-Access, for an instance).

If it works, then build the jdbc-odbc bridge URL as stated above and
see what happens. 

At last, bear in mind that nobody really recomends the jdbc-odbc bridge
to production applications. 

Roque

--- aldo <[email protected]> wrote:
> thank you Rouque
> Yes, I can connect to the db through the SQL*+, also I have cheked
> the 
> file tnsnames, and I found out that the SERVICE_NAME=aldo.prova, thus
> I've 
> gone into the code at the line below and put aldo.prova instead of
> just 
> aldo
> String sourceURL=new String("jdbc:odbc:aldo.prova");
> now when I run my code I got another error message:
> Java.sql.SQLException[Microsoft][ODBC Driver Manager] the source name
> of 
> the data has not been found and default driver not set???
> Aldo
> 
> > ORA-12514 means that a Net8 client was unable to create a
> connection to
> a database. Net8 clients try to create connection with basis on the
> tnsnames.ora file's content. Have you checked this file? Are you able
> to establish a db connection using any other tool - like Oracle
> SQL*Plus?
> 
> Roque Daudt
> 
> --- aldo <[email protected]> wrote:
> > 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%%.
> 
> 
> __________________________________________________
> Do you Yahoo!?
> Yahoo! Mail Plus - Powerful. Affordable. Sign up now.
> http://mailplus.yahoo.com
> ---
> Change your mail options at http://p2p.wrox.com/manager.asp or 
> to unsubscribe send a blank email to
%%email.unsub%%.


__________________________________________________
Do you Yahoo!?
Yahoo! Mail Plus - Powerful. Affordable. Sign up now.
http://mailplus.yahoo.com

---
Change your mail options at http://p2p.wrox.com/manager.asp or 
to unsubscribe send a blank email to [email protected].
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.