Sir, I am not getting any fault in my code but the code is not executing with the demands which I have.
I just want to register 2 values into the database using jsp , if the username is present in the database it will show User already exist otherwise it will insert the values but its not working. please help me out.
JSP CODE
<%@page import="java.sql.*" %>
<% Class c = Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection conn = DriverManager.getConnection("jdbc:odbc:inventory","sa","12345");
String uname = request.getParameter("username");
String pwd = request.getParameter("password");
PreparedStatement ps = conn.prepareStatement("SELECT * from Login");
ResultSet rs=ps.executeQuery();
int flag = 1;
while(rs.next())
{
String UNAME=rs.getString("User_Name");
if(uname.equalsIgnoreCase(UNAME))
{ flag=0;}
}
if(flag==0)
out.println("Username already exists!!!");
else {
PreparedStatement ps1=conn.prepareStatement("INSERT into Login values(?,?)");
ps1.setString(1,uname);
ps1.setString(2, pwd);
ps1.executeUpdate();
out.println("Registered Successfully");
}
%>
HTML CODE
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<form action="register.jsp" method="GET">
<p>Enter Username : <input type="text" name="username" value="" /></p>
<p>Enter your Password : <input type="password" name="password" value="" /></p>
<p><input type="submit" value="Register Now" /></p>
</form>
</body>
</html>