/********************************************************************
*
* StateQueryAns.java
*
* Last Modified: 5/12/00
*
* This servlet is the "action" of StateQueryForm. It gets the
* data input by the user, namely the name of the state, and then
* query the database and display an HTML page with the querying
* results.
*
********************************************************************/
import java.io.*;
import java.text.*;
import java.util.*;
import java.sql.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class StateQueryAns extends HttpServlet
{
public static String USERNAME = new String("user");
public static String PASSWORD = new String("pass");
public void doPost(HttpServletRequest request,
HttpServletResponse response)
throws IOException, ServletException
{
String stateName = request.getParameter("statename");
String state_capital = "";
String state_flower = "";
String state_bird = "";
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.println("");
out.println("
");
if (stateName != null)
{
out.println("" + "You have requested info for " + stateName + "");
out.println("");
out.println("");
try
{
// Load the Oracle Driver
Class.forName("oracle.jdbc.driver.OracleDriver");
}
catch(ClassNotFoundException e)
{
}
try
{
// Get a connection from the connection factory
Connection con = DriverManager.getConnection(
"jdbc:oracle:thin:@oracle-prod:1521:8PRD", USERNAME, PASSWORD);
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery("SELECT CAPITAL, FLOWER, BIRD FROM STATE WHERE NAME = '" + stateName + "'");
while(rs.next())
{
state_capital = rs.getString("CAPITAL");
state_flower = rs.getString("FLOWER");
state_bird = rs.getString("BIRD");
//out.println("State Name: " + state_name + "Capital: " + state_capital);
}
}
catch (SQLException e)
{
}
if(state_capital.equals(""))
{
out.println("No info for State " + stateName + "");
}
else
{
out.println("State " + stateName + " has capital at " + state_capital + "
");
out.println("The State Flower of " + stateName + " is " + state_flower + "
");
out.println("The State Bird of " + stateName + " is " + state_bird + "
");
}
}
else
{
out.println("" + "You have not requested a state name" + "");
out.println("");
out.println("");
}
out.println("");
out.println("");
}
}