1 24 25 package edu.rice.rubbos.servlets; 26 27 import java.io.IOException ; 28 import java.sql.Connection ; 29 import java.sql.PreparedStatement ; 30 import java.sql.ResultSet ; 31 32 import javax.servlet.ServletException ; 33 import javax.servlet.http.HttpServletRequest ; 34 import javax.servlet.http.HttpServletResponse ; 35 36 public class RejectStory extends RubbosHttpServlet 37 { 38 39 public int getPoolSize() 40 { 41 return Config.BrowseCategoriesPoolSize; 42 } 43 44 private void closeConnection(PreparedStatement stmt, Connection conn) 45 { 46 try 47 { 48 if (stmt != null) 49 stmt.close(); } 51 catch (Exception ignore) 52 { 53 } 54 55 try 56 { 57 if (conn != null) 58 releaseConnection(conn); 59 } 60 catch (Exception ignore) 61 { 62 } 63 64 } 65 66 67 public void doGet(HttpServletRequest request, HttpServletResponse response) 68 throws IOException , ServletException 69 { 70 71 ServletPrinter sp = null; 72 PreparedStatement stmt = null; 73 Connection conn = null; 74 75 sp = new ServletPrinter(response, "RejectStory"); 76 77 String storyId; 78 79 ResultSet rs = null; 80 int updateResult; 81 82 storyId = request.getParameter("storyId"); 83 84 if (storyId == null) 85 { 86 sp 87 .printHTML("RejectStory: <h3>You must provide a story identifier !<br></h3>"); 88 return; 89 } 90 91 sp.printHTMLheader("RUBBoS: Story submission result"); 92 sp.printHTML("<center><h2>Story submission result:</h2></center><p>\n"); 93 94 conn = getConnection(); 95 96 try 97 { 98 stmt = conn.prepareStatement("SELECT id FROM submissions WHERE id=" 99 + storyId); 100 rs = stmt.executeQuery(); 101 } 102 catch (Exception e) 103 { 104 sp.printHTML("Failed to execute Query for RejectStory: " + e); 105 closeConnection(stmt, conn); 106 return; 107 } 108 try 109 { 110 if (!rs.first()) 111 { 112 sp 113 .printHTML("<h3>ERROR: Sorry, but this story does not exist.</h3><br>\n"); 114 closeConnection(stmt, conn); 115 return; 116 } 117 118 stmt.close(); 119 120 stmt = conn.prepareStatement("DELETE FROM submissions WHERE id=" 122 + storyId); 123 updateResult = stmt.executeUpdate(); 124 } 125 catch (Exception e) 126 { 127 sp.printHTML("Exception rejecting story: " + e + "<br>"); 128 closeConnection(stmt, conn); 129 return; 130 } 131 132 closeConnection(stmt, conn); 133 134 sp 135 .printHTML("The story has been successfully removed from the submissions database table<br>\n"); 136 137 sp.printHTMLfooter(); 138 139 } 140 141 public void doPost(HttpServletRequest request, HttpServletResponse response) 142 throws IOException , ServletException 143 { 144 doGet(request, response); 145 } 146 147 } 148 | Popular Tags |