#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2002
    Posts
    1
    Rep Power
    0

    Open Oracle DB in JSP


    I'm trying to locate an example of a simple JSP that opens an Oracle DB and displays the contents of a table. I didn't think it would be this difficult! All the examples and tutorials want me to build large projects and all I want to do is creat one JSP much the way I would take care of it in ColdFusion with a single .CFM.
    Can anyone enlighten me? Am I missing something?

    Thanks,

    Jim
  2. #2
  3. Modding: Oracle MsSQL Firebird
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jun 2001
    Location
    Outside US
    Posts
    8,527
    Rep Power
    539
    Take a look at this example:
    <%@ page import="java.sql.*" %>
    <HTML>
    <HEAD><TITLE>Simple Oracle Example</TITLE></HEAD>
    <BODY BGCOLOR="#FFFFFF">
    <CENTER>
    <B>Employees</B>
    <BR><BR>

    <%
    Connection conn = null;
    try
    {
    Class.forName("oracle.jdbc.driver.OracleDriver");

    conn = DriverManager.getConnection(
    "jdbcracle:thin:@HOST:PORT:SID",
    "scott",
    "tiger");

    Statement stmt = conn.createStatement();
    ResultSet rs = stmt.executeQuery("SELECT * FROM Example.Emp");

    //Print start of table and column headers
    out.println("<TABLE CELLSPACING=\"0\" CELLPADDING=\"3\" BORDER=\"1\">");
    out.println("<TR><TH>ID</TH><TH>NAME</TH></TR>");

    //Loop through results of query.
    while(rs.next())
    {
    out.println("<TR>");
    out.println("<TD>" + rs.getString("EmpID") + "</TD>");
    out.println("<TD>" + rs.getString("Name") + "</TD>");
    out.println("</TR>");
    }

    out.println("</TABLE>");
    }
    catch(SQLException e)
    {
    out.println("SQLException: " + e.getMessage() + "<BR>");
    while((e = e.getNextException()) != null)
    out.println(e.getMessage() + "<BR>");
    }
    catch(ClassNotFoundException e)
    {
    out.println("ClassNotFoundException: " + e.getMessage() + "<BR>");
    }
    finally
    {
    //Clean up resources, close the connection.
    if(conn != null)
    {
    try
    {
    conn.close();
    }
    catch (Exception ignored) {}
    }
    }
    %>

    </CENTER>
    </BODY>
    </HTML>
    taken from http://elab-nt1.bus.umich.edu/howto_oracle_jsp.html http://www.classicity.com/oracle/htd...mID124/10.html

IMN logo majestic logo threadwatch logo seochat tools logo