JSP & Oracle

Discussions

Web tier: servlets, JSP, Web frameworks: JSP & Oracle

  1. JSP & Oracle (5 messages)

    Hi All,
    Can anybody tell me the steps required to connect to the oracle database from a JSP page.
    I want the information like, how to make dsn, which oracel drivers are needed.... what code shud be written in the JSP page and other relevant information.
    Thanks
    Nitu.

    Threaded Messages (5)

  2. JSP & Oracle[ Go to top ]

    String dbUrl = N2PProperties.getProperty("system", "file.jdbcpool.url");

    ResultSet rs=null;
    PreparedStatement ps = null;
    Connection con=null;

    try{
    con=DriverManager.getConnection(dbUrl);

    ps=con.prepareStatement("sql statement");
    rs= ps.executeQuery();

    while(rs.next()){
    setString(1, field)
    setInt(2,field)
    }
    }catch(Exception ex){
    throw new Exception(ex.toString());
    }

    finally{
           try{
    if(ps != null) ps.close();
    if(rs != null)rs.close();
    if(con != null)con.close();
    }catch( SQLException e){
    throw new Exception();
    }catch(Exception e){
    throw new Exception();
    }
    }

  3. JSP & Oracle[ Go to top ]

    <html>
    <body>
    <%@ page import="java.io.*,java.sql.*;"%>

    <%String login,pwd;
    try
    {
    login=request.getParameter("t1");
    pwd=request.getParameter("t2");
    Connection con;
    Statement st;
    Class.forName("oracle.jdbc.driver.OracleDriver");
    con=DriverManager.getConnection("jdbc:oracle:thin:@nms:1525:db1","sridhar","raju");
    st=con.createStatement();
    ResultSet rs=st.executeQuery("select * from sushma where name='"+login+"'");
    if(!rs.next())
    {
    PreparedStatement pst=con.prepareStatement("insert into sushma values(?,?)");
    pst.setString(1,login);
    pst.setString(2,pwd);
    int x=pst.executeUpdate();
    if(x>0)
    out.print("<h1>Insertion is sucessful</h1>");
    else
    out.print("<h1>Insertion is failed</h1>");
    }
    else
    out.print("<h1>The username already exist</h1>");
    }
    catch(Exception e){e.printStackTrace();}
    %>
    </body></html>


  4. JSP & Oracle[ Go to top ]

    thanks,
    but i am getting an error.. it says...
    java.lang.ClassNotFoundException: oracle.jdbc.driver.OracleDriver
    (i am using weblogic server)...
    where do i find these... or do i have to download some driver and then set the classpath..
    awaiting reply soon..
    thnks
    nitu
  5. JSP & Oracle[ Go to top ]


    That error is coming because the oracle driver is not in the
    classpath. That driver is available with oracle client named classes12.zip or classes111.zip. put these zip files in the weblogic class path. these zip files will be in <installed directory>/oracle/ora81/jdbc/lib directory ( if ur working on oracle 8.1.1).

    If the same error continues unzip the classes12.zip or classes111.zip in which u will find the class file for oracle driver. better unzip in the same lib folder and give that in the classpath.

    Instead of all these...u can also use JdbcOdbcDriver
    create a dsn for that oracle. u can write the same code
    that u write generally in java class file for database connection. but write that code in <% %> tags.

    bye
    ravi.
  6. JSP & Oracle[ Go to top ]

    Yes I agree with my friend.
    Instead of using type-4 JDBC vendor specific driver, it is advisible to go for type-1 driver for conncecting to major databases like SQL server, Oracle,MySQL..

    type-1 is good for development purpose , but for production release its is advisible to go for type-4 driver.
    But, then the bridge driver is not very stable and can give birth to unexpected issues.

    anyways u may try...it

    Vijay Khanna