JSP data base validation

Ads
 

JSP data base validation

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

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
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
Advertisements
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
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 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
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
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 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
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
ModuleNotFoundError: No module named 'odoo11-addon-base-tier-validation'
ModuleNotFoundError: No module named 'odoo11-addon-base-tier-validation' ...: ModuleNotFoundError: No module named 'odoo11-addon-base-tier-validation' How to remove the ModuleNotFoundError: No module named 'odoo11-addon-base-tier-validation'
ModuleNotFoundError: No module named 'odoo11-addon-base-tier-validation'
ModuleNotFoundError: No module named 'odoo11-addon-base-tier-validation' ...: ModuleNotFoundError: No module named 'odoo11-addon-base-tier-validation' How to remove the ModuleNotFoundError: No module named 'odoo11-addon-base-tier-validation'
ModuleNotFoundError: No module named 'odoo11-addon-base-tier-validation'
ModuleNotFoundError: No module named 'odoo11-addon-base-tier-validation' ...: ModuleNotFoundError: No module named 'odoo11-addon-base-tier-validation' How to remove the ModuleNotFoundError: No module named 'odoo11-addon-base-tier-validation'
ModuleNotFoundError: No module named 'odoo12-addon-base-tier-validation'
ModuleNotFoundError: No module named 'odoo12-addon-base-tier-validation' ...: ModuleNotFoundError: No module named 'odoo12-addon-base-tier-validation' How to remove the ModuleNotFoundError: No module named 'odoo12-addon-base-tier-validation'
ModuleNotFoundError: No module named 'odoo12-addon-base-tier-validation'
ModuleNotFoundError: No module named 'odoo12-addon-base-tier-validation' ...: ModuleNotFoundError: No module named 'odoo12-addon-base-tier-validation' How to remove the ModuleNotFoundError: No module named 'odoo12-addon-base-tier-validation'
ModuleNotFoundError: No module named 'odoo12-addon-base-tier-validation'
ModuleNotFoundError: No module named 'odoo12-addon-base-tier-validation' ...: ModuleNotFoundError: No module named 'odoo12-addon-base-tier-validation' How to remove the ModuleNotFoundError: No module named 'odoo12-addon-base-tier-validation'
ModuleNotFoundError: No module named 'odoo13-addon-base-tier-validation'
ModuleNotFoundError: No module named 'odoo13-addon-base-tier-validation' ...: ModuleNotFoundError: No module named 'odoo13-addon-base-tier-validation' How to remove the ModuleNotFoundError: No module named 'odoo13-addon-base-tier-validation'
ModuleNotFoundError: No module named 'odoo10-addon-base-tier-validation'
ModuleNotFoundError: No module named 'odoo10-addon-base-tier-validation' ...: ModuleNotFoundError: No module named 'odoo10-addon-base-tier-validation' How to remove the ModuleNotFoundError: No module named 'odoo10-addon-base-tier-validation'
ModuleNotFoundError: No module named 'odoo9-addon-base-tier-validation'
ModuleNotFoundError: No module named 'odoo9-addon-base-tier-validation' ...: ModuleNotFoundError: No module named 'odoo9-addon-base-tier-validation' How to remove the ModuleNotFoundError: No module named 'odoo9-addon-base-tier-validation'
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
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
ModuleNotFoundError: No module named 'tensorflow-data-validation'
ModuleNotFoundError: No module named 'tensorflow-data-validation'  Hi...: No module named 'tensorflow-data-validation' How to remove the ModuleNotFoundError: No module named 'tensorflow-data-validation' error? Thanks
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
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
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
ModuleNotFoundError: No module named 'odoo11-addon-base-tier-validation-formula'
ModuleNotFoundError: No module named 'odoo11-addon-base-tier-validation-formula...: ModuleNotFoundError: No module named 'odoo11-addon-base-tier-validation-formula... odoo11-addon-base-tier-validation-formula After the installation of odoo11-addon
ModuleNotFoundError: No module named 'odoo11-addon-base-tier-validation-formula'
ModuleNotFoundError: No module named 'odoo11-addon-base-tier-validation-formula...: ModuleNotFoundError: No module named 'odoo11-addon-base-tier-validation-formula... odoo11-addon-base-tier-validation-formula After the installation of odoo11-addon
ModuleNotFoundError: No module named 'odoo12-addon-base-tier-validation-formula'
ModuleNotFoundError: No module named 'odoo12-addon-base-tier-validation-formula...: ModuleNotFoundError: No module named 'odoo12-addon-base-tier-validation-formula... odoo12-addon-base-tier-validation-formula After the installation of odoo12-addon
ModuleNotFoundError: No module named 'odoo12-addon-base-tier-validation-formula'
ModuleNotFoundError: No module named 'odoo12-addon-base-tier-validation-formula...: ModuleNotFoundError: No module named 'odoo12-addon-base-tier-validation-formula... odoo12-addon-base-tier-validation-formula After the installation of odoo12-addon
ModuleNotFoundError: No module named 'odoo12-addon-base-tier-validation-formula'
ModuleNotFoundError: No module named 'odoo12-addon-base-tier-validation-formula...: ModuleNotFoundError: No module named 'odoo12-addon-base-tier-validation-formula... odoo12-addon-base-tier-validation-formula After the installation of odoo12-addon
ModuleNotFoundError: No module named 'odoo13-addon-base-tier-validation-formula'
ModuleNotFoundError: No module named 'odoo13-addon-base-tier-validation-formula...: ModuleNotFoundError: No module named 'odoo13-addon-base-tier-validation-formula... odoo13-addon-base-tier-validation-formula After the installation of odoo13-addon

Ads