• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Connecting to Oracle 7 thru jdbc

 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi there,

Can anyone tell me how to connect to an Oracle 7 database using jdbc?
I've got the correct jdbc drivers. I can connect to the database fine if I connect within a normal java application from the command line.
But as soon as I connect within a servlet I get a "No suitable driver found" exception.

Please help.

Thanks

Fathima Khan
 
author
Posts: 3892
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You'll need to tell us what Servlet container you are using in order for us to help you. Also, which drivers you are using and how you set them up in the container would be useful to know as well.

Kyle
 
Rida Abrahams
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi there again,

Thanks for the reply. I am running Tomcat 4 on Linux Redhat 6. I am not sure how the database administrator set the drivers up or which drivers I am using.
I do know that by testing the database connection using a normal java program from the command line does work and does return data from the oracle database.

here is the init method where i am specifying the driver name:

public void init() {

try {
DriverManager.registerDriver (new oracle.jdbc.driver.OracleDriver());
Class.forName("oracle.jdbc.driver.OracleDriver");
System.out.println("JDBC driver loaded");
}

catch (ClassNotFoundException e) {
System.out.println(e.toString());
}

catch (SQLException e) {
System.out.println(e.toString());
}
}

and this is how I'm getting my connection:

Connection con = DriverManager.getConnection("jdbc racle:thin:@192.96.74.6:1521:bndb", "sb", "sb");

I have imported these packages:
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;
import java.sql.*;

I don't know if any of this info will be helpful in determining which drivers I am using though. Someone told me that I needed to add the location of the jdbc drivers to my Java classpath and my Tomcat classpath. Do you know if that is correct?

Thanks.
 
Ranch Hand
Posts: 572
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

DriverManager.registerDriver (new oracle.jdbc.driver.OracleDriver());
Class.forName("oracle.jdbc.driver.OracleDriver");



Why are you registering drivers 2 times? Its enough to write

DriverManager.registerDriver (new oracle.jdbc.driver.OracleDriver());
Connection con = DriverManager.getConnection();
 
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

Are you sure you have dropped Oracle's JDBC driver in your WEB-INF/libs?

Regards,
Francis
 
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
OK, time to move this to a more appropriate forum.

This forum is for Servlets questions.

I will move this thread to the JDBC forum

Mark
 
Put the moon back where you found it! We need it for tides and poetry and stuff. Like this tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic