Wall Script
Follow Me:
Sunday, February 14, 2010

Live Availability Checking with Java.

Some days I had posted an article about User name live availability checking with PHP and jquery. In this post my brother Ravi Tamada explained the same with Java technologies like JSP and servelts using MySQL database.

Live Availability Checking with Java.

Download Script     Live Demo

About Author
Ravi Tamada
Computer science engineering, Final Year
India, Twitter Profile @ravi8x
( ravi8x[at]gmail.com )

You just download the script copy and paste the directory into Tomcat Webapps directory
MySQL users table columns uid, uname, passcode.
passcode VARCHAR(50)

$('#uname').change(function(){} - uname is the ID of the input. Using $("#uname").val() calling input field value. First checking the value string length max 3 (uname.length > 3)
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript">
var uname = $(this).val();
if(uname.length > 3)
$(".status").html("Checking availability...");
type: "POST",
url: "check",
data: "uname="+ uname,
success: function(msg)
$(".status").ajaxComplete(function(event, request, settings)

$(".status").html("username shold be 3 chars");


<label>user name :</label>
<input type="text" class="uname"/><span class="status"></span>

Contains java code. Download link Mysql Java Connector Jar file
import java.io.*;
import java.sql.*;
import javax.servlet.ServletException;
import javax.servlet.http.*;

public class check extends HttpServlet
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
PrintWriter out = response.getWriter();
// 9lessons is my database name
String connectionURL = "jdbc:mysql://localhost:3306/9lessons";
Connection connection = null;
connection = DriverManager.getConnection(connectionURL, "root", "root");
String uname = request.getParameter("uname");
PreparedStatement ps = connection.prepareStatement("select uname from USERS where uname=?");
ResultSet rs = ps.executeQuery();

if (!rs.next())
out.println("<b>"+uname+"</b> is avaliable");
out.println("<font color=red><b>"+uname+"</b> is already in use</font>");
catch (Exception ex)
out.println("Error ->" + ex.getMessage());
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
doPost(request, response);
Anonymous said...


Karthik said...

Very useful site !!
Please include Google custom search in ur website.
(google.com/webelements )
difficult to use blogger's default search for finding things.

sorrisosv said...

how can i prevent my page from doing the registration if the user use the username already use in the username field? tks

Yudz said...

this is nice. i was looking for something like this. however i need help about some part of it.

i use xampp for apache and mysql for my php system. i have a module in java that i need to connect. the java should go to that same database to retrieve values. how is can be achieved?

also, can you provide some links to help me learn further about the mysql java connector and tomcat.


Stevens said...

Excelent code Ravi!

one question this works very well on FireFox and Opera but not in IE, when you type any letter and hit enter key notghing appears!, any clues ??


Ravi Kumar said...


Hello Steve thanx for ur comment. In this code i write code for invoking an event only when we change the content in the TEXT FIELD, this is done when we come out from the TEXT FIELD not when hitting ENTER key. This works in firefox when hitting ENTER key, this may be fire fox feature n in opera and IE hitting enter is not working.

infopediaonlinehere said...

this is an interesting script...i never thought there is a way in java to do this...thank you ravi

demo said...

is this script well secured .i hope its not prone to hackers.

demo said...

i want to know if its possible to insert an image button where you have it available

Diaa Kasem said...

I like the post .. thank you ..

Anonymous said...

Nice...but can't get it to work :-(
Copied all files into myapps
Engineers explain things so other engineers can understand :-)

Great I'm sure !

Anonymous said...

nice article but not work completely.when the error displayed the cursor not moved to the next field...
Best luck

Anonymous said...

please help me... its urgent... the code is working fine.. but its posting the form even if the username already existed... i want to stop this please help me how should i do this.....

How are you Hacher! said...

good one,
very useful in my project

Anonymous said...

please help me. it urgent .this code is working but i need to disable the submit button when the user i already exist?

Anonymous said...

it's not working m getting error..
n.extend.ajax jquery.min.js:19
(anonymous function) register1.jsp:19
n.event.handle jquery.min.js:19
(anonymous function)

Anonymous said...

if get valid username then only navigate to next textbox otherwise onfocus in usename textbox how to validate in the example of (Live Availability Checking with Java). any one tell me

Post a Comment