Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.server -> Re: Configuring Oracle for JDBC

Re: Configuring Oracle for JDBC

From: <joeNOSPAM_at_BEA.com>
Date: 27 Aug 2006 18:06:46 -0700
Message-ID: <1156727206.507143.163510@h48g2000cwc.googlegroups.com>

jmecc_at_telus.net wrote:
> You're right, but changing the 'HOST' in tnsnames.ora and listener.ora
> still doesn't allow the connection to be made despite the listener
> service starting without error in all cases. Although I have used (a
> bit) Linux and Oracle, I am new to setting both of them up so I may
> just be overlooking some parameter change or something.
>
> >From fresh error-free Linux & Oracle installations, what are the steps
> I need to take to make this machine accept JDBC connections? I am
> hoping someone knows a good tutorial; I have looked at many but they
> all explain how to install Linux/Oracle or how to use JDBC while none I
> have seen explain the part in the middle about getting this connection
> to work.
>
> Thanks,
> Jo

Hi. I highly recommend using Oracle's JDBC driver in the thin mode, not the OCI/tnsnames.ora method. All you need is the machine name where the DBMS is running (or localhost if on the same box), the listener port (1521), and the SID (assuming a valid username and password:

import java.util.*;
import java.io.*;
import java.sql.*;

public class thin_connect_demo
{
 public static void main(String argv[]) throws Exception  {
   Connection c = null;
   try
   {
     Driver dr =
(Driver)Class.forName("oracle.jdbc.OracleDriver").newInstance();

     Properties props = new Properties();
     props.put("user", "scott");
     props.put("password", "tiger");

     c = dr.connect("jdbc:oracle:thin:@MYDBMSBOX:1521:MYSID", props);
     System.out.println("The driver is " +
c.getMetaData().getDriverVersion() );
     System.out.println("The DBMS is " +
c.getMetaData().getDatabaseProductVersion() );

   }
   catch (Exception e)
   {

       e.printStackTrace();
   }
   finally {

       try {c.close();} catch (Exception ignore){}    }
 }
}

Joe Weinstein at BEA Systems Received on Sun Aug 27 2006 - 20:06:46 CDT

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US