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



Home Answers Viewqa JSP-Servlet JSP data base validation
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


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

 

 

DMCA.com