Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

JSP connection to Oracle

Options
  • 14-04-2004 1:01pm
    #1
    Closed Accounts Posts: 1,521 ✭✭✭


    I'm trying to connect to an Oracle 8 database with JSP pages. This is the connection code I am using and it doesn't seem to be working at all.

    <%@ page import="java.sql.*, javax.sql.*" %>

    <%

    Class.forName("oracle.jdbc.driver.OracleDriver");

    DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());

    Connection con = DriverManager.getConnection(“jdbc:oracle:thin:@WITNT07.wit.ie:1521:ORAWIT, “W99490510”, “UKQHUJ”);

    String driver_id=request.getParameter("driver_id");
    String name=request.getParameter("name");
    String date_of_birth=request.getParameter("date_of_birth");
    String bank_details=request.getParameter("bank_details");
    String contact_details=request.getParameter("contact_details");
    String licence=request.getParameter("licence");

    Statement stmt=con.createStatement();

    ResultSet rs=stmt.executeUpdate("insert into driver

    (driver_id,name,date_of_birth,bank_details,contact_details,licence)
    values('"+driver_id+"','"+name+"','"+date_of_birth+"','"+bank_details+"','"+contact_details+"','"+licence+"')");

    %>

    <%
    stmt.close();
    con.close();
    %>

    I think the problem is the drivers but don't know what drivers I'm supposed to use. I'd appreciate any help on this, thanks.


Comments

  • Registered Users Posts: 261 ✭✭r0chf0rt


    Whats the exact error message ?


  • Closed Accounts Posts: 1,651 ✭✭✭Enygma


    have you got the Oracle drivers in your WEB-INF/lib folder? It's probably just a jar file: oracle*.jar
    Can't remember what it's called, haven't used Oracle in ages.

    Post the error


  • Registered Users Posts: 602 ✭✭✭soma


    Can U post the exact error message pls. Oracle throws a variety of error msgs when it comes to JDBC and I've probably seen them all at this point....

    Otherwise we're just fumbliing in the dark here..

    finally - eh, at the risk of sounding like a purist here... this is a really bad way to write your code and will be a maintenance nightmare if any of your connection details change (imagine trawling through tens of jsps changing ip addresses/SID's etc..).

    To avoid this you should have some sort of middle layer like a servlet but if this is too much work you should at *least* write a class (a singleton) that can be reused across your jsps so if your connection details/sql statements change then you only have to make changes in one place.

    There are several good java pattern books out there that can help you with this sort of thing.

    back to the problem.. just post the error msg pls..


  • Closed Accounts Posts: 1,651 ✭✭✭Enygma


    I usually use a ConnectionFactory class to get a Connection from a ConnectionPool.
    This way you get a connection throughout your app by doing something like this:
    con = ConnectionFactory.getConnection();
    stmt = con.prepareStatement.....
    

    The ConnectionPool is got using JNDI and the connection parameters are in the server.xml file.

    Works nicely for me.


Advertisement