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(" JDBC CONNECTION to mySQL."); out.println("

**** JDBCServlet ****

"); /* load the Driver to mySQL.......... */ try { Class.forName("org.gjt.mm.mysql.Driver"); } catch (ClassNotFoundException e) { out.println(e.toString()); } // end catch /* create the connection .......... */ try { String url = "jdbc:mysql:location"; Connection con = DriverManager.getConnection (url); Statement stmt = con.createStatement(); 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