Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Connecting to Oracle 7 thru jdbc

 
Rida Abrahams
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • 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
 
Kyle Brown
author
Ranch Hand
Posts: 3892
5
  • Mark post as helpful
  • send pies
  • 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
  • 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.
 
Ali Gohar
Ranch Hand
Posts: 572
  • Mark post as helpful
  • send pies
  • 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();
 
Francis Amanfo
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

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

Regards,
Francis
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • 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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic