import javax.servlet.*; import javax.servlet.http.*; import java.io.*; import java.util.*; import java.sql.*; public class JDBCservlet extends HttpServlet { public void service(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException { String location_name = new String(); String queryString = new String(); queryString = ("SELECT * FROM Test ORDER BY 1"); /* set the output content type and get an output stream for the response */ res.setContentType("text/html"); ServletOutputStream out = res.getOutputStream(); out.println("
RETRIEVE ALL ROWS FROM TEST TABLE
"); ResultSet rs = stmt.executeQuery(queryString); out.println(""); while (rs.next()) { String s = rs.getString(2); int i = rs.gerInt(1); out.println(s, i); } out.println(""); out.println(" "); /* flush and close the OutputStream*/ out.flush(); out.close(); /* Close the result set */ rs.close(); /* Close the statement */ stmt.close(); /* Close the connection */ con.close(); } // end try catch (Exception e) { out.println(e.toString()); } // end catch } // end of service method } // end of class JDBCServlet