Guest User

Untitled

a guest
Jun 16th, 2013
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.16 KB | None | 0 0
  1. <%@ page language="java" contentType="text/html; charset=windows-1255"
  2. pageEncoding="windows-1255"%>
  3. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  4. <%@ page import ="java.sql.*" %>
  5.  
  6. <%!
  7. void connectDB(){
  8. try {
  9. Class.forName("com.mysql.jdbc.Driver").newInstance();
  10. connection = DriverManager.getConnection(connectionURL, "root", "root");
  11. statement = connection.createStatement();
  12. } catch (Exception e) {
  13. System.out.println("error in connecting");
  14. }
  15. }
  16. %>
  17. <html>
  18. <head>
  19.  
  20. <title>JSP Page</title>
  21. </head>
  22. <body>
  23. <%
  24. connectDB();
  25. int no=0;
  26. rs = statement.executeQuery("SELECT * FROM users");
  27. while (rs.next()) {
  28. no++;
  29. }
  30. if(no==0)
  31. response.sendRedirect("errorsearch.html");
  32. rs.close();
  33.  
  34.  
  35.  
  36. String queryString = "DELETE FROM users WHERE trim(username)='" +request.getParameter("username") + "'";
  37. try {
  38. int n = statement.executeUpdate(queryString);
  39. statement.close();
  40. connection.close();
  41. } catch (SQLException ex) {
  42. System.out.println("SQLException: " + ex.getMessage());
  43. System.out.println("SQLState: " + ex.getSQLState());
  44. }
  45. response.sendRedirect("usershow.jsp");
  46. %>
  47. </body>
  48. </html>
Advertisement
Add Comment
Please, Sign In to add comment