jbdc connection

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
act1veAsked:
Who is Participating?
 
objectsConnect With a Mentor Commented:
> but there is no lib directory inside this?

just create one
0
 
objectsCommented:
> I have downloaded the jbdc connection driver and placed it into the /WEB-INF folder of tomcat.

should be in WEB-INF/lib
0
 
objectsCommented:
   } 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
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
objectsCommented:
> 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
 
act1veAuthor Commented:
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
 
act1veAuthor Commented:
yep, i will unignore those lines thanks, that should help some
0
 
act1veAuthor Commented:
ah ok thanks, didnt know you could just do that, i will attempt that now
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.