Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- protected void doPost(HttpServletRequest request, HttpServletResponse response)
- throws ServletException, IOException {
- response.setContentType("text/html;charset=UTF-8");
- PrintWriter out = response.getWriter();
- try {
- String connectionURL = "jdbc:mysql://localhost:3306/dbName";
- Connection connection = null;
- Class.forName("com.mysql.jdbc.Driver").newInstance();
- connection = DriverManager.getConnection(connectionURL, "root", "");
- String uname = request.getParameter("uname");
- PreparedStatement ps = connection.prepareStatement("SELECT Username from users where Username=?"); // users is the table containg used usernemes
- ps.setString(1,uname);
- ResultSet rs = ps.executeQuery();
- if (!rs.next()) {
- out.println("<font color=green><i class=\"fa\"></i> <b>"+uname+"</b> is available");
- }
- else{
- out.println("<font color=red><i class=\"fa\"></i> Sorry, but <b>"+uname+"</b> is not available</font>");
- }
- out.println();
- } catch (Exception ex) {
- out.println("Error ->" + ex.getMessage());
- } finally {
- out.close();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement