JDBC connection problem ...

I am trying to connect to an Oracle database located on a hp box and my development is
 primarily on an NT box. I am using the function getconnection to access the database in the following fashion.
conn = DriverManager.getConnection ("jdbc:oracle:dnldthin:@myhost:3202:isdev11", "userid", "password");
Is there something that I am missing????



 
aswinmajjAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

mkaCommented:
Hi,

A lot depends upon how your Oracle is configured. Hoping everything is fine there and you have the Oracle driver classes, look at the sample below. Compare what you have in your program as against my sample.

/*
 * This sample applet just selects 'Hello World' and the date from the database
 */

// Import the JDBC classes
import java.sql.*;

// Import the java classes used in applets
import java.awt.*;
import java.io.*;
import java.util.*;

public class JdbcApplet extends java.applet.Applet
{
  // The driver to load
  static final String driver_class = "oracle.jdbc.driver.OracleDriver";

  // The connect string
  static final String connect_string =
                  "jdbc:oracle:thin:scott/tiger@dlsun511:1721:dbms733";

  // This is the kind of string you woudl use if going through the
  // Oracle 8 connection manager which lets you run the database on a
  // different host than the Web Server.  See the on-line documentation
  // for more information.
  // static final String connect_string = "jdbc:oracle:thin:scott/tiger@(description=(address_list=(address=(protocol=tcp)(host=dlsun511)(port=1610))(address=(protocol=tcp)(host=pkrishna-pc2)(port=1521)))(source_route=yes)(connect_data=(sid=orcl)))";

  // The query we will execute
  static final String query = "select 'Hello JDBC: ' || sysdate from dual";
 

  // The button to push for executing the query
  Button execute_button;

  // The place where to dump the query result
  TextArea output;

  // The connection to the database
  Connection conn;

  // Create the User Interface
  public void init ()
  {
    this.setLayout (new BorderLayout ());
    Panel p = new Panel ();
    p.setLayout (new FlowLayout (FlowLayout.LEFT));
    execute_button = new Button ("Hello JDBC");
    p.add (execute_button);
    this.add ("North", p);
    output = new TextArea (10, 60);
    this.add ("Center", output);
  }

  // Do the work
  public boolean action (Event ev, Object arg)
  {
    if (ev.target == execute_button)
    {
      try
      {
      // Clear the output area
      output.setText (null);

      // See if we need to open the connection to the database
      if (conn == null)
      {
        // Load the JDBC driver
        output.appendText ("Loading JDBC driver " + driver_class + "\n");
        Class.forName (driver_class);

        // Connect to the databse
        output.appendText ("Connecting to " + connect_string + "\n");
        conn = DriverManager.getConnection (connect_string);
        output.appendText ("Connected\n");
      }

      // Create a statement
      Statement stmt = conn.createStatement ();

      // Execute the query
      output.appendText ("Executing query " + query + "\n");
      ResultSet rset = stmt.executeQuery (query);

      // Dump the result
      while (rset.next ())
        output.appendText (rset.getString (1) + "\n");

      // We're done
      output.appendText ("done.\n");
      }
      catch (Exception e)
      {
      // Oops
      output.appendText (e.getMessage () + "\n");
      }
      return true;
    }
    else
      return false;
  }
}

The program is 'over-systematic', but it is written like that for a purpose. I couldn't write one to suit you, though this should be enough.

Thanks.
Kaleem.
0
aswinmajjAuthor Commented:
Can u tell me how u'r oracle should be configured??? From what I understand I can access the oracle database from the unix command prompt. Also do I need the webserver to run on the hp machine??

Thanks
0
mkaCommented:
Hi,

You'll need the Oracle webserver only in case you are to execute your program as an applet on the browser -- about which you have made no mention in your question. I do not know anything about your configuration of Oracle - like your installation is a Oracle Server or you have Oracle Server running as a host machine on the network etc etc. When you can access it from the command prompt -- the only thing that could be troubling your connection from a Java program could very well be the driver classes for Oracle. Double check your code for the presence of  a statements like the below:
// The driver to load
   static final String driver_class = "oracle.jdbc.driver.OracleDriver";

and:
  // Load the JDBC driver
   output.appendText ("Loading JDBC driver " + driver_class + "\n");
   Class.forName (driver_class);  // This loads the driver.

Also check whether you really posses oracle.jdbc.driver.OracleDriver in one of you .jar or .zip's in your classpath. Without any of these, an Oracle database connection through Java cannot through.

Since you mentioned Win NT, you can use WinZip to see the contents of .zip and .jar files -- and look in .zip files in the directory jdbc or something like that; and file names like classes111.zip, etc.

If you don't have the driver classes; you'll have to procure them.

Thanks.
Kaleem.
0
Why Diversity in Tech Matters

Kesha Williams, certified professional and software developer, explores the imbalance of diversity in the world of technology -- especially when it comes to hiring women. She showcases ways she's making a difference through the Colors of STEM program.

evijayCommented:
Hi,

Checkup whether the tnslsnr is running and tnsnames.ora is having all the correct details. Tell me one thing. Are you able to access oracle from windows client using tns ? If you are not then your jdbc driver will fail too. First checkup whether you are able to access oracle thru tns.

The following things can be done
In the unix machine check up whether a process by name
tnslsnr is running or not using ps command. If it is not running run it. Before doing this, configure tnsnames.ora to have proper value (in solaris it is in /var/opt/oracle).

try the following command
sqlplus userid/password@isdev11   (isdev11 is your tns name)
if it succeeds then your unix part is ok

Next step is go to nt part. you must have oracle client installed in the system. use tnsneteasy config to configure the tns names. suppose your tns alias is comdev then try giving
sqlplus userid/password@comdev. if connection succeeds then everything is fine in both nt and unix. Next try your program. If it still doesnt work send me a comment.



0
aswinmajjAuthor Commented:
Let me put down the scenario again in front of u guys:
1) I can perform sqlplus from the command prompt in unix
2) Downloaded the oracle driver
3) The code looks like the following
import java.sql.*;
import java.awt.*;
import java.io.*;
import java.util.*;
public class JdbcApplet extends java.applet.Applet{
  static final String driver_class = "oracle.jdbc.dnlddriver.OracleDriver";  
  string static final
 public void init ()
  {
    this.setLayout (new BorderLayout ());
 
   Panel p = new Panel ();
 
  p.setLayout (new FlowLayout (FlowLayout.LEFT));
 
   execute_button = new Button ("Hello JDBC");
 
  p.add (execute_button);
   
 this.add ("North", p);
 
  output = new TextArea (10, 60);
   
 this.add ("Center", output);
  }
public boolean action (Event ev, Object arg)
  {
   
 if (ev.target == execute_button)
 
  {
      try
      {
      // Clear the output area
      output.setText (null);

      
// See if we need to open the connection to the database
      
if (conn == null)
      {
        // Load the JDBC driver
                  output.appendText ("Beyond class" + driver_class + "\n");
        output.appendText ("Loading JDBC driver " + driver_class + "\n");
        Class.forName(driver_class);
      
  output.appendText ("Beyond class" + driver_class + "\n");
      
  // Connect to the database
      
 output.appendText ("Connecting to " + connect_string + "\n");
      
  conn = DriverManager.getConnection("jdbc:oracle:dnldthin:@myhost:isdev11", "userid", "password");
      
  output.appendText ("Connected\n");
      }


4) I don't have a httpd server running on the Unix box ...

THanks

-- aswin

0
mkaCommented:
Hi,

Now you are speaking stuff. Without the code about we'd be trying all combinations of replies here. Thanks for giving your code.

The problem is with the line:
conn = DriverManager.getConnection("jdbc:oracle:dnldthin:@myhost:isdev11", "userid", "password");

What is "isdev11"? Since you are working on HP, it appears you are using UNIX 'dev' term to denote the UNIX terminal. (Tell me if I am wrong.)

Check whether "isdev11" is a valid database name in Oracle. Your understanding of JDBC appears to be that connection is made with the terminal or client or network machine. No, instead the connection is made with a database instance in the Oracle database. A database connection then allows you to access all the tables and views in the database.

Besides that, your code seems to be okay to me.

If you are executing from appletviewer, then you should get the database connection immediately. However, if you are trying to execute the applet through a browser, you'll be in pain till you get a database server like Oracle server.

Thanks.
Kaleem.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.