[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

jbdc connection

Posted on 2005-04-08
7
Medium Priority
?
232 Views
Last Modified: 2010-04-01
Im trying to connect to an oracle database with jsp and tomcat.

My code to connect to the database is:

<%

    Connection connection = null;
    try {
        // Load the JDBC driver
        String driverName = "oracle.jdbc.driver.OracleDriver";
        Class.forName(driverName);
   
        // Create a connection to the database
        String serverName = "myhostname";
        String portNumber = "1521";
        String sid = "MACH";
        String url = "jdbc:oracle:thin:@" + serverName + ":" + portNumber + ":" + sid;
        String username = "myusername";
        String password = "mypassword";
        connection = DriverManager.getConnection(url, username, password);
    } catch (ClassNotFoundException e) {
        // Could not find the database driver
    } catch (SQLException e) {
        // Could not connect to the database
    }

%>

which i think looks ok. I have downloaded the jbdc connection driver and placed it into the /WEB-INF folder of tomcat. The file is classes111.zip, is it necessary to unzip these files into there?

I then have a small query which is below:

<%@ include file="db.jsp"%>

<%

Select * from Supervisor;

%>


does this all seem correct? i'm not able to make the connection, tomcat displays erros which i believe are to do with it not finding the connection driver?

Any help would be appreciated
0
Comment
Question by:act1ve
  • 4
  • 3
7 Comments
 
LVL 92

Expert Comment

by:objects
ID: 13734264
> I have downloaded the jbdc connection driver and placed it into the /WEB-INF folder of tomcat.

should be in WEB-INF/lib
0
 
LVL 92

Expert Comment

by:objects
ID: 13734269
   } catch (ClassNotFoundException e) {
        // Could not find the database driver
    } catch (SQLException e) {
        // Could not connect to the database
    }

You're also ignoring exception so you'll have no idea what exactly is the cause of the error
0
 
LVL 92

Expert Comment

by:objects
ID: 13734281
> Select * from Supervisor;

And you can't just insert sql list that, the following shows how to send a query

http://www.javaalmanac.com/egs/java.sql/CreateResultSet.html
http://www.javaalmanac.com/egs/java.sql/GetRsData.html?l=rel
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:act1ve
ID: 13734283
thanks for the fast response, i cant seem to find /lib,

i have: Tomcat4\webapps\ROOT\WEB-INF, but there is no lib directory inside this?
0
 

Author Comment

by:act1ve
ID: 13734299
yep, i will unignore those lines thanks, that should help some
0
 
LVL 92

Accepted Solution

by:
objects earned 2000 total points
ID: 13734306
> but there is no lib directory inside this?

just create one
0
 

Author Comment

by:act1ve
ID: 13734310
ah ok thanks, didnt know you could just do that, i will attempt that now
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If anyone asked you to network diagram of the internet, it was drawn in the form of a fluffy cloud which further became known as cloud computing. Popularly cloud computing is defined as workloads that run over the internet in a commercial provider’s…
MSSQL DB-maintenance also needs implementation of multiple activities. However, unprecedented errors can hamper the database management. In that case, deploying Stellar SQL Database Toolkit ensures fast and accurate database and backup repair as wel…
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Loops Section Overview
Suggested Courses

873 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question