Accessing Oracle tables from a web page


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3

Thread: Accessing Oracle tables from a web page

  1. #1
    Serge Guest

    Accessing Oracle tables from a web page


    I am in the process of creating a small application where a person would
    choose from a list of state codes, press a submit button, and then access
    an Oracle table to return all area codes for that state.
    I have just started programming in Java and HTML, so I don't know enough
    yet on how to go about programming this.
    The page was created in Web Factory. We have Java, Unix, and oracle here.
    If anyone out there could point me in the right direction, it would be much
    appreciated.
    Thanks

  2. #2
    John Butorac Guest

    Re: Accessing Oracle tables from a web page

    I'm assuming that this is being developed for the web...and since you have
    java I'm also assuming that you can process servlets and jsp files...

    I would write a servlet, and use JDBC to connect to the oracle database and
    then display the appropriate results. A simple example of how this is done
    is as follows:

    //*****************************************************************
    import java.io.*;
    import java.sql.*;
    import javax.servlet.*;
    import javax.servlet.http.*;


    public class ClassName extends HttpServlet {

    public void doGet (HttpServletRequest req, HttpServletResponse res) throws
    ServletException, IOException
    {
    Connection con = null;
    Statement stmt = null;
    ResultSet rs = null;

    res.setContentType("text/html");
    PrintWriter out = res.getWriter();

    try {
    // load and therefore register the MySQL Driver
    Class.forName("org.xxx.xx.mysql.Driver");

    // get a connection to the db
    con =
    DriverManager.getConnection("jdbc:mysql://www.xx.xxxxxx.com:1212/secur1?user
    =SystemAdmin&password=Password");

    // Create a statement object
    stmt = con.createStatement();

    // execute a sql query, get a resultset
    rs = stmt.executeQuery("SELECT Employee_ID, First_Name, Last_Name FROM
    tbl_Employee_file;");

    // start writing the html
    out.println("<HTML><head><title>This is my title</title></head>");

    out.println("<body>");
    out.println("<table>");

    // interate through the resultset and display the contents
    while(rs.next()) {
    out.println("<tr><td>" + rs.getString("Employee_ID") + " </td><td> " +
    rs.getString("First_Name") + " </td><td> " + rs.getString("Last_Name") +
    "</td></tr>");
    }

    out.println("</table>");
    out.println("</html>");
    }

    catch(ClassNotFoundException e) {
    out.println("Couldn't load the db driver: " + e.getMessage());
    }

    catch(SQLException e) {
    out.println("SQLException caught.: " + e.getMessage());
    }

    finally {
    try {
    if (con != null) con.close();
    }
    catch (SQLException ignored) { }
    }
    }
    }
    //**************************************************************************
    *******************************


    This should at least get you started. Look in sun's site for additional
    help on the matter. Hope that this helps.





    "Serge" <serge.small@wcom.com> wrote in message
    news:3a67469b@news.devx.com...
    >
    > I am in the process of creating a small application where a person would
    > choose from a list of state codes, press a submit button, and then access
    > an Oracle table to return all area codes for that state.
    > I have just started programming in Java and HTML, so I don't know enough
    > yet on how to go about programming this.
    > The page was created in Web Factory. We have Java, Unix, and oracle here.
    > If anyone out there could point me in the right direction, it would be

    much
    > appreciated.
    > Thanks




  3. #3
    John Butorac Guest

    Re: Accessing Oracle tables from a web page

    I forgot one thing (at least)...

    // you can grab the state code in the servlet with this statement
    String State_Code = req.getParameter("ST")
    // where ST is the name of the combobox or whatever control lists the state
    codes


    "John Butorac" <jbutorac@nlamerica.com> wrote in message
    news:3a677410@news.devx.com...
    > I'm assuming that this is being developed for the web...and since you have
    > java I'm also assuming that you can process servlets and jsp files...
    >
    > I would write a servlet, and use JDBC to connect to the oracle database

    and
    > then display the appropriate results. A simple example of how this is

    done
    > is as follows:
    >
    > //*****************************************************************
    > import java.io.*;
    > import java.sql.*;
    > import javax.servlet.*;
    > import javax.servlet.http.*;
    >
    >
    > public class ClassName extends HttpServlet {
    >
    > public void doGet (HttpServletRequest req, HttpServletResponse res)

    throws
    > ServletException, IOException
    > {
    > Connection con = null;
    > Statement stmt = null;
    > ResultSet rs = null;
    >
    > res.setContentType("text/html");
    > PrintWriter out = res.getWriter();
    >
    > try {
    > // load and therefore register the MySQL Driver
    > Class.forName("org.xxx.xx.mysql.Driver");
    >
    > // get a connection to the db
    > con =
    >

    DriverManager.getConnection("jdbc:mysql://www.xx.xxxxxx.com:1212/secur1?user
    > =SystemAdmin&password=Password");
    >
    > // Create a statement object
    > stmt = con.createStatement();
    >
    > // execute a sql query, get a resultset
    > rs = stmt.executeQuery("SELECT Employee_ID, First_Name, Last_Name FROM
    > tbl_Employee_file;");
    >
    > // start writing the html
    > out.println("<HTML><head><title>This is my title</title></head>");
    >
    > out.println("<body>");
    > out.println("<table>");
    >
    > // interate through the resultset and display the contents
    > while(rs.next()) {
    > out.println("<tr><td>" + rs.getString("Employee_ID") + " </td><td> " +
    > rs.getString("First_Name") + " </td><td> " + rs.getString("Last_Name") +
    > "</td></tr>");
    > }
    >
    > out.println("</table>");
    > out.println("</html>");
    > }
    >
    > catch(ClassNotFoundException e) {
    > out.println("Couldn't load the db driver: " + e.getMessage());
    > }
    >
    > catch(SQLException e) {
    > out.println("SQLException caught.: " + e.getMessage());
    > }
    >
    > finally {
    > try {
    > if (con != null) con.close();
    > }
    > catch (SQLException ignored) { }
    > }
    > }
    > }
    >

    //**************************************************************************
    > *******************************
    >
    >
    > This should at least get you started. Look in sun's site for additional
    > help on the matter. Hope that this helps.
    >
    >
    >
    >
    >
    > "Serge" <serge.small@wcom.com> wrote in message
    > news:3a67469b@news.devx.com...
    > >
    > > I am in the process of creating a small application where a person

    would
    > > choose from a list of state codes, press a submit button, and then

    access
    > > an Oracle table to return all area codes for that state.
    > > I have just started programming in Java and HTML, so I don't know

    enough
    > > yet on how to go about programming this.
    > > The page was created in Web Factory. We have Java, Unix, and oracle

    here.
    > > If anyone out there could point me in the right direction, it would be

    > much
    > > appreciated.
    > > Thanks

    >
    >




Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center