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

Home -> Community -> Usenet -> c.d.o.misc -> Re: new to jdbc-oracle

Re: new to jdbc-oracle

From: steve <E_at_E.COM>
Date: Thu, 13 Dec 2001 06:18:13 +0800
Message-ID: <1f4cc0w.1dotexol8juo0N%E@E.COM>


HI,
THIS IS WHAT I USE TO START WITH A CONNECTION, use the following to allow u to try different connevction strings etc. don't hardcode.

this will make a connection ready to pass quiries to the oracle.

User ="EXTERNAL_USER"; Password ="EXTERNAL_USER";

 String Site ="192.168.2.1:1521:orcl"; //internal testing

public Statement Open_odbc(String Site ,String User,String Password)

          {
           Statement stmt=null; 
          try
      {
       // open the connection to the database
       Class.forName ("oracle.jdbc.driver.OracleDriver");
       // Connect to the database
       
  
         
       dbconn =  DriverManager.getConnection ("jdbc:oracle:thin:@"+Site
,User,Password);
      //this is needed
        dbconn.setAutoCommit(false);
        stmt = dbconn.createStatement ();

      }
     catch (Exception e)
      {
       handleError(e);
      }
        return stmt;
        }
        








Rob Zwartjes <rzwartje_at_rob.home.nl> wrote:

> Hai,
> I have installed oracle 8.1.6 on linux ( SuSE 7.2) and have trouble
> running the script below :
>
> import java.sql.*;
> import oracle.jdbc.driver.*;
>
> class JDBCVersion
> {
> public static void main (String args[]) throws SQLException
> {
> // Load the Oracle JDBC driver
> DriverManager.registerDriver
> (new oracle.jdbc.driver.OracleDriver());
> Connection conn = DriverManager.getConnection
> ("jdbc:oracle:thin:@home:1521:TEST","name","passw");
>
> // Create Oracle databaseMetaData object
> DatabaseMetaData meta = conn.getMetaData();
>
> // get drivers info:
> System.out.print("JDBC driver version is " + meta.getDriverVersion());
> }
> }
> This little script comes from oracle doc A81354-01.pdf. After running :
> javac GetDriverVersion.java ( name of the script above ),
> chmod u+x GetDriverVersion.java ( to make it a exe ) and
> typed GetDriverVersion.java to run it.
> The only thing I get is a fat cross in my console window. Nothing else.
> The values after the @ sign I retrieved from tnsnames.ora because I
> didn't know what else to fill in for host, port and sid. Changing thin to
> oci8 and putting after the @ sign TEST.ROB.NL ( from tnsnames.ora)
> didn't solve my problem. Classpath has been set btw. And for the oci8
> the LD_LIBRARY_PATH
> What am I forgetting ????? or overlooking ???
>
> Thanks in advance for your time,
>
> Rob
Received on Wed Dec 12 2001 - 16:18:13 CST

Original text of this message

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