Advertisement
Guest User

Untitled

a guest
Jul 14th, 2018
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.33 KB | None | 0 0
  1. protected void doPost(HttpServletRequest request, HttpServletResponse response)
  2. throws ServletException, IOException {
  3. response.setContentType("text/html;charset=UTF-8");
  4. PrintWriter out = response.getWriter();
  5. try {
  6.  
  7. String connectionURL = "jdbc:mysql://localhost:3306/dbName";
  8. Connection connection = null;
  9. Class.forName("com.mysql.jdbc.Driver").newInstance();
  10. connection = DriverManager.getConnection(connectionURL, "root", "");
  11. String uname = request.getParameter("uname");
  12. PreparedStatement ps = connection.prepareStatement("SELECT Username from users where Username=?"); // users is the table containg used usernemes
  13. ps.setString(1,uname);
  14. ResultSet rs = ps.executeQuery();
  15.  
  16. if (!rs.next()) {
  17. out.println("<font color=green><i class=\"fa\">&#xf058;</i>&nbsp;<b>"+uname+"</b> is available");
  18. }
  19. else{
  20. out.println("<font color=red><i class=\"fa\">&#xf12a;</i>&nbsp;Sorry, but <b>"+uname+"</b> is not available</font>");
  21. }
  22. out.println();
  23.  
  24.  
  25.  
  26. } catch (Exception ex) {
  27.  
  28. out.println("Error ->" + ex.getMessage());
  29.  
  30. } finally {
  31. out.close();
  32. }
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement