JSP data base validation

Ads

 
 

Share on Google+Share on Google+

kartik desai
JSP data base validation
2 Answer(s)      4 years and 5 months ago
Posted in : JSP-Servlet

please explain how to validate form input string with database n also how its notify that entered data exists already .please reply soon

Ads
View Answers

May 18, 2013 at 1:29 PM


hi friend,

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<%@ page import="java.sql.*" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Registration Form</title>
</head>
<body>
<form action="#">
<center><h2>Registration Form</h2></center>
<table>
<tr>
<td>Student ID</td>
<td><input type="text" name="id"/></td>
</tr>
<tr>
<td>Student Name</td>
<td><input type="text" name="sName"/></td>
</tr>
<tr>
<td>Phone No</td>
<td><input type="text" name="phno"/></td>
</tr>
<tr>
<td></td>
<td><input type="submit" value="submit"/></td>
</tr>
</table>
</form>
<%
String driver = "com.mysql.jdbc.Driver";
String url = "jdbc:mysql://localhost:3306/record";
String user = "root";
String password = "root";
String id = request.getParameter("id");
String name = request.getParameter("sName");
String phno = request.getParameter("phno");
String sql = "insert into student2(id, sName, phno) values(?,?,?)";
String sql2 = "select * from student2 where phno = ?";

Connection con = null;
PreparedStatement ps = null;
PreparedStatement ps1 = null;
ResultSet rs = null;

Continue...



May 18, 2013 at 1:30 PM


if(request.getParameter("id") != null)
{
    int sId = Integer.parseInt(id);
    int sPhno = Integer.parseInt(phno); 
    try
    {
        Class.forName(driver);
        con = DriverManager.getConnection(url, user, password);
        ps1 = con.prepareStatement(sql2);
        ps1.setInt(1, sPhno);       
        rs = ps1.executeQuery();        
        if(rs.next())
        {
            int ssId = rs.getInt("id");
            int ssPhno = rs.getInt("phno");
            String ssName = rs.getString("sName");
            if(((sId == ssId && sPhno == ssPhno) || (name.equals(ssName) && sPhno == ssPhno)) || (name.equals(ssName) && sId == ssId))
            {
                out.println("Record Already Existed");
            }
            else
            {
                ps = con.prepareStatement(sql);
                ps.setInt(1,sId);
                ps.setString(2,name);       
                ps.setInt(3,sPhno);
                boolean bol = ps.execute();
                out.println("Data Added Successfully");
            }
        }
        else
        {           
            ps = con.prepareStatement(sql);
            ps.setInt(1,sId);
            ps.setString(2,name);       
            ps.setInt(3,sPhno);
            boolean bol = ps.execute();
            out.println("Data Added Successfully");
        }       
    }
    catch(Exception e)
    {
        out.println("SQL Error : "+ e);
    }   
}
%>
</body>
</html>

Thanks.


Ads









Related Tutorials/Questions & Answers:
JSP data base validation
JSP data base validation  please explain how to validate form input string with database n also how its notify that entered data exists already... bol = ps.execute(); out.println("Data Added Successfully
for store data in data base - JSP-Servlet
for store data in data base  i want to a job site, in this site user..... and on 3rd form i use submit button... data of form 1 and 2 can also be store... Friend, We have created 4 jsp files: 1)login.jsp: A:hover
Advertisements
data (image ,audio) inserting to data base (oracle 10g) and retriving the same data from jsp
data (image ,audio) inserting to data base (oracle 10g) and retriving the same data from jsp   data (image ,audio) inserting to data base (oracle 10g) and retriving the same data from jsp with script of data base plz help me
Retrieving data from data base using jsp combo box
Retrieving data from data base using jsp combo box  Hi guys please help me , i have on GUI page int that Server type(like apache,jboss,weblogic) one combo box is there and another filed is version of the server(like 1.0,2.0) like
data fecth from data base in( sql 2000) htmlform and jsp
data fecth from data base in( sql 2000) htmlform and jsp  hi iam using jsp and html form data fecth from database display the textbox help me i want whenever select from dropdown list select the projectname to display
how to insert the bulk data into the data base from the table of jsp page to another jsp page
how to insert the bulk data into the data base from the table of jsp page to another jsp page  pls help i'm doing the project called centralized... to insert the marks details into the data base i have retrive the rollno and name
data base
data base  how to connect coding in data base ?   The given code connects JSP page to database. You need to import the mysql connection jar file to jdk as well as to the lib of tomcat. Moreover you need to set classpath
DATA BASE
DATA BASE  Create a program to establish a connection to the PCTBC... the data using a J Table.   Here is a code that connects to MySql... main(String[] args) { Vector columnNames = new Vector(); Vector data = new Vector
getting int values from form and insert it in data base in jsp
getting int values from form and insert it in data base in jsp  how... = Integer.parseInt(s); Then you can write JDBC code to insert data...=st.executeUpdate("insert into data(name,age, address) values('"+name+"',"+age
Validation.... - JSP-Servlet
Validation....  in registration page. if i entered an Logine name , which all ready in the data base. how i can get the appropiate msg like "User all ready in the data base" in my data base User ID is the primary key and Login
data validation by maker and checker
data validation by maker and checker  My requirment is like ,an user will view some records in a jsp page,and two buttons will be there in that page... different functions of multiple buttons in a jsp page and how to fetch next row
jsp validation
jsp validation  enter name-___ enter number-__ I want that the focus should not go to number till the time u have entered name. Means the number text should be disabled.. i require code
Data base Connectivity
Data base Connectivity  How to configure JDBC connection for Oracle data base.In configuring it is asking select Data server name and TNS.I typed Oracle for Data Server Name and IN TNS what to type? I pulled the list for TNS
validation - JSP-Servlet
side validation and when you submit the form it passes the data to some file over... .jsp. Required fields are-: 1.login 2.password 3.Firstname 4.lastname...,jsp,beans demo of all these to facilitate how to write code... iam very
Data base related question
Data base related question  sir my table has only one element(that is pno),i am using ms-access as backend. i put only one element i want to retrieve that element .how can i retrieve that element,using jdbc technology. please
value is inserted into the sql table through jsp-jdbc but not getting stored into the data base,only row is increasing.
value is inserted into the sql table through jsp-jdbc but not getting stored into the data base,only row is increasing.  <html> <..."> <title>JSP Page</title> <style type
Data base - JDBC
Data base  I want to do this Inserting a record with Object type column using PreparedStatement but wht should b the column datatype this is te..."); con.close(); }//main }//class For this should i create a user defined data type
validation - JSP-Servlet
, Please visit the following link to have an example of user validation in JSP page with the MySQL database. http://www.roseindia.net/mysql
jsp-oracle validation - JDBC
jsp-oracle validation  Dear friends, my validation not takes place..., Implement validation code. Insert into database function...://www.roseindia.net/jsp/ Thanks. Amardeep   Hello I am try so many times
please send me the banking data base in swings
please send me the banking data base in swings  sir, please send me how to create the banking data base program in swings
Struts validation for j-query tabs data
Struts validation for j-query tabs data  Hi, I want apply struts validation for J-query tabs data while saving into database, can any body tell please
jsp+ajax validation
jsp+ajax validation  hi, I have created the jsp form (course... have created student jsp form where it should display register number... 60% in the drop down list .how to validate student from using ajax and jsp
Retrive the data from the table in data base using jdbc
Retrive the data from the table in data base using jdbc  Retrive the data from the table in data base using jdbc   JDBC Tutorials
retrive data from data base and print it in every page until logout
retrive data from data base and print it in every page until logout  suppose that a user login your website through user name & password. now... in JSP
JSP-jdbc validation - JSP-Servlet
JSP-jdbc validation  How to validate login email id using JSP, where..., login application in jsp function validateForm(theForm... for more information. http://www.roseindia.net/jsp/valid-email
java validation problem - JSP-Servlet
java validation problem  I have created a Registration page.I want validate the username entered by the user at the time he enters the username.How... problem. Here is the link http://www.roseindia.net/jsp/user-registration-form
Radio button validation using jsp - JSP-Servlet
Radio button validation using jsp  I had one jsp Page and servlet. I did my validations in servlet for my jsp page which contains the radio... a value for radio Buttons) then it will return to same jsp page with the given
validation before entering values into database in jsp
validation before entering values into database in jsp  Hi, my project involves entering data into database from jsp form.but before entering into database it should pop up a alert message that "you have selected product:name
when refreshing the page the data is stored in data base again
when refreshing the page the data is stored in data base again  Hi, In my application, I am adding form data in database on click of submit button.But the problem is, when user refreshes the page, the data added one more time
login form validation - JSP-Servlet
login form validation  hi, how to validate the login form that contains user name and password using post method . the validation should not allow user to login in the address bar thanks regards, anand
data base question - Java Interview Questions
data base question  first we create a table with out create primary kay,after that i want to create same record with primary key,but no duplicate record,no deletion and after creation.  Hi, Query to create

Ads

 
Advertisement null

Ads