Simply make the HTML form's action to call a servlet:

    <form method="post" action="/servlet/dbQuery">
        <select name="code" option value="">Select a
Description</option>
            <option value="1">Student</option>
            <option value="2">Faculty</option>
            <option value="3">Others</option>
        </select>
    </form>

which would get the option's value (presumably, the code):

    String code = request.getParameter( "code");

and insert it into a JDBC select statement:

    try {
        Class.forName( "oracle.jdbc.driver.OracleDriver");
        Connection con = DriverManager.getConnection(
"jdbc:oracle:thin:dbhost:1528:ORCL", "user", "pw");
        Statement stmt = con.createStatement();
        ResultSet rs = stmt.executeQuery( "SELECT [whatever] FROM
[myTable] WHERE code = " + code);

and display the result set as an HTML page:

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

        out.println( "<html><head><title>Query
Results</title></head>");
        out.println( "<body>");
        out.println( "Query results:");
        while( rs.next()) {
            out.println( rs.getString( "description") + " = code " +
rs.getString( "code"));
        }
        out.println( "</body><html>");
    } catch( ClassNotFoundException e) {
        out.println( e.getMessage());
    } catch( SQLException e) {
        out.println( e.getMessage());
    } finally {
        try {
            if( con != null) con.close();
        } catch( SQLException e) {
            out.prinln( e.getMessage());
        }
    }


Cheers!
Mark

----- Original Message -----
From: "Neeta Patil" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Sunday, April 08, 2001 8:07 AM


> Hi !!
> Is it possible to create a browsable and editable database in
tabular format
> using servlets? This operation should be on the browser i.e Netscape
and IE.
> And
> I have a table with following columns
> ------------------
> code | description
> ------------------
> 1    | student
> 2    | faculty
> 3    | others
> .    | ...
> .    | ...
> .    |....
>
> 50   |....
> ------------------
> Now I want to take these values and display description in the HTML
form
> (<select> <option value=  >) so that the user can select from the
options
> since as the number of type of member grows it's not possible to
remember
> the codes.
> Any ideas how is it possible to do so, so that if the table changes
those
> changes are reflected in the <select><option>    </select> list?
> Thanx,
> -Neeta
>
______________________________________________________________________
___
> Get Your Private, Free E-mail from MSN Hotmail at
http://www.hotmail.com.
>
>
______________________________________________________________________
_____
> To unsubscribe, send email to [EMAIL PROTECTED] and include in
the body
> of the message "signoff SERVLET-INTEREST".
>
> Archives:
http://archives.java.sun.com/archives/servlet-interest.html
> Resources:
http://java.sun.com/products/servlet/external-resources.html
> LISTSERV Help: http://www.lsoft.com/manuals/user/user.html
>

___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".

Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html

Reply via email to