Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa JSP-Servlet JSP data base validation

Have Programming Question? Ask it here!
 
 
 


kartik desai
JSP data base validation
2 Answer(s)      a year and 2 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


Advertisement
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.



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 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
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 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
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
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
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
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
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
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
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
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
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
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
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
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
Struts2 and Hibernate Fetch Data Base Value
Struts2 and Hibernate Fetch Data Base Value  Hello Sir, I am facing the problem while fetching the database value on jsp page while using... me what should i do for fetch the database value and shown on jsp page
Struts2 and Hibernate Fetch Data Base Value
Struts2 and Hibernate Fetch Data Base Value  Hello Sir, I am facing the problem while fetching the database value on jsp page while using... me what should i do for fetch the database value and shown on jsp page
insert excel value in to oracle data base
insert excel value in to oracle data base  Hi All I am using...); System.out.println("Data is inserted... the data from the excel file using JDBC. For this you need to create dsn
java code for threading example for connecting data base
java code for threading example for connecting data base  Write a program that has two threads First thread queries the database and fetches all the employee records from the emp table. Stores the employee objects
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
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
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
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
How to create a Student data base using Linked List in java
How to create a Student data base using Linked List in java  I want a program by using linked list in java. The data stored must... no to display: "); String rec=input.next(); for(StudentData data:list
How to create a data base connectivity using sqlserver or Mydql through J2ME - JDBC
How to create a data base connectivity using sqlserver or Mydql through J2ME   hi , iam new to J2ME,i want to know, How to create a data base... with the sqlserver2000 database. so i want to update the data into database as well
J2ME Record Data Base
J2ME Record Data Base       This Application is used to explain how to store data in the database... the RecordStore class. The RecordStore class is used to get the data through
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
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
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
validation
validation  validation
validation
validation  we are doing payroll system project in java.So pls provide the complete validation code for employee master form
combox validation javascript code - JSP-Servlet
combox validation javascript code  hiiiiiii, I want a javascript code for combobox field validation for my Lotus Notes web page.... thnx  Hi This is the source code of combobox validation in javascript
Validation
[]columns={"Name","Number","Price"}; Object[][]data={ {"A",new Integer(01),new... Integer(400)} }; model=new DefaultTableModel(data,columns); JTable table = new JTable(data, columns); JLabel headerRenderer = new DefaultTableCellRenderer
validation.....
validation.....  hi.......... thanks for ur reply for validation code. but i want a very simple code in java swings where user is allowed to enter only numerical values in textbox , if he enters string values then it should
validation
Validation method valid the in put. otherwise call the javascript onsubmit to check... code.Ok if you use struts then you can use Validation method valid the in put
validation
validation  please help me to check validation for <form> <table class="form"> <tr> <td class="col1"> <label>Sno:</label> </td> <td
Date validation in JSP
Date validation in JSP       Example for validating date in a specified format in a JSP page This example illustrates how to use date validation in a JSP page. Here in this code we are using
base the value of first combo box, how i display the second combox - JSP-Servlet
base the value of first combo box, how i display the second combox    i have a combo box for classes. my requirement is when i select the class... let me how i implement this in JSP. Class Subject Art
Validation
). How do i perform a check using JAVA on the data before storing...(); ResultSet rs=st.executeQuery("select * from data where email='"+value1...("insert into data(email,contactNo) values('"+value1+"','"+value2
validation
form using spring ,hibernate and jsp my all classes and jsp pages are pasted..." prefix="form"%> <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%> <%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix
data grid - JSP-Servlet
to implement data grid in jsp Thanks varun kumar  Hi friend, I... information. http://www.roseindia.net/jsp/data-grid.shtml Thanks...data grid  how can we implement data grid (we have data grid
jsp data in excel - JSP-Servlet
jsp data in excel  i have create jsp page which has button for excel.this calls jsp which contains code which has and then code for present data in jsp using table. and getting this data from servlet which has query
 

 

 

DMCA.com