package org.usi2011; import java.io.IOException; import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; import javax.servlet.ServletException; import javax.servlet.ServletOutputStream; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; /** * Servlet implementation class question */ public class Question extends HttpServlet { private static final long serialVersionUID = 1L; private Connection connection; /** * Default constructor. */ public Question() { super(); connection = Database.getConnection(); } /** * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse * response) */ protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { ServletOutputStream out = response.getOutputStream(); try { String query = "INSERT INTO game VALUES (1, 2, 3, 4, 5)"; Statement statement = connection.createStatement(); ResultSet resultset = statement.executeQuery(query); query = "SELECT * FROM game"; statement = connection.createStatement(); resultset = statement.executeQuery(query); while (resultset.next()) { out.println(resultset.getString(1)); } } catch (SQLException e) { response.sendError(400); } out.println("hello world"); out.println(request.getRequestURI()); } /** * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse * response) */ protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // TODO Auto-generated method stub } }