
i am created one table in mysql database with one of the column name is emailid.now i want to write a java code that if the mail id is already exit then it will show this emailid is already exit otherwise it will show you can register now. thanks pls reply soon

The given code accepts the email id from the user and check whether the given email id already exists or not. If it is already exist in database, then show a message 'Already exists'. Otherwise, it will show a message 'You can register now!'.
1)availability.jsp:
<html>
<head>
<script type="text/javascript">
function check(value){
xmlHttp=GetXmlHttpObject()
var url="checkajax.jsp";
url=url+"?email="+value;
xmlHttp.onreadystatechange=stateChanged
xmlHttp.open("GET",url,true)
xmlHttp.send(null)
}
function stateChanged(){
if(xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){
var showdata = xmlHttp.responseText;
document.getElementById("mydiv").innerHTML= showdata;
}
}
function GetXmlHttpObject(){
var xmlHttp=null;
try{
xmlHttp=new XMLHttpRequest();
}
catch (e) {
try {
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e){
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
}
return xmlHttp;
}
</script>
</head>
<body>
<form name="form">
Email Id: <input type="text" name="email" id="email" onkeyup="check(this.value);"><font color="red"><div id="mydiv"></div></font>
</form>
</body>
</html>
2)checkajax.jsp:
<%@ page import="java.sql.*" %>
<%
String name = request.getParameter("email").toString();
System.out.println(name);
String data ="";
try{
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/test", "root", "root");
Statement st=con.createStatement();
ResultSet rs=st.executeQuery("select * from login where email='"+email+"'");
int count=0;
while(rs.next())
{
count++;
}
if(count>0)
{
data="Email-ID already exists!";
}
else
{
data="You can register now!!!!";
}
out.println(data);
System.out.println(data);
}
catch (Exception e) {
System.out.println(e);
}
%>
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.