Programming error

Programming error

<%--<%@ page language="java" import="java.sql.*" %>
<%

Connection con=null;
ResultSet rs=null;
Statement stmt=null;

try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con=DriverManager.getConnection("jdbc:odbc:Advdsn");
stmt=con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
ResultSet_CONCUR_READ_ONLY);
rs=s.executeQuery("select OrderNo from OrderTab");
while(rs.last())
{
int Ono=Integer.parseInt(rs.getInt(1));
int No=Ono+1;
}
}
catch(SQLException se)
{out.println("Database error="+se.getMessage());
}

catch(Exception e)
{out.println("Error="+e.getMessage());
}


%>--%>


<HTML>
<HEAD>
<TITLE> Place Order </TITLE>
<script type="text/javascript">
function Validate()
{
var valid=true;
if(document.forms.OrderNo.value=="")
{ alert("Please enter valid OrderNo");
valid=false;
}
if(document.forms.Name.value=="")
{ alert("Please enter valid Client's Name");
valid=false;
}
if(document.forms.Address.value=="")
{ alert("Please enter valid Client's Address");
valid=false;
}
if(document.forms.Email.value=="")
{ alert("Please enter valid Email ID");
valid=false;
}
if(document.forms.PhoneNo.value=="")
{ alert("Please enter valid PhoneNo");
valid=false;
}
return valid;
}
</script>
</HEAD>

<BODY BGCOLOR="lightblue">
<marquee behavior="alternate" scrollamount=5 scrolldelay=10>
<h1><font size=4 face="Stroustroup" color="#993355">Advertisement Management System</h1></font></marquee><br>

<hr color="green">
<form method="post" onsubmit="return Validate();" name="forms" action="http://localhost:8080/ProjectAd/Orders">
<p align=center><b>Order No:&nbsp;&nbsp;&nbsp;<input type=text name="OrderNo" size=25 value<%="No"%></b>
<p align=center><b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Name:&nbsp;&nbsp;&nbsp;<input type=text name="Name" size=25 ></b>
<p align=center><b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Address:&nbsp;&nbsp;<textarea name="Address" rows=5 cols=25 size=25></textarea></b>
<p align=center><b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Email:&nbsp;&nbsp;<input type=text name="Email" size=25></b>
<p align=center><b>PhoneNo:&nbsp;&nbsp;<input type=text name="PhoneNo" size=25></b><br><br>
<p align=center><b><a href="http://localhost:8080/ProjectAd/Orders"><input type=submit name=submit value="Insert Order"></a></b>
<b><input type=reset name=reset value="Reset"></b>
<a href="http://localhost:8080/ProjectAd/Update.jsp"><b><h4 align=center>Update Orders</h4></b></a>
<a href="http://localhost:8080/ProjectAd/Delete.jsp"><b><h4 align=center>Delete Orders</h4></b></a>
<a href="http://localhost:8080/ProjectAd/View.jsp"><b><h4 align=center>View Orders</h4></b></a>
<a href="http://localhost:8080/ProjectAd/PlaceOrd.jsp"><b><h4 align=center>Back </h4></b></a></p>
<p align=center><a href="http://localhost:8080/ProjectAd/MainPage.html"><img src="images/home_ap.jpg" height=20 width=20>MainPage</a>
</form>
<hr color="green">
</BODY>
</HTML>

how to validate email field where if @ is not given or (dot). is not given etc then it should display error and in phone no field people can enter only 8 or 10 digits no and no alphabet and in orderno people should not enter alphabet and in other 2 field such as name and pwd where user should not enter number please reply me and i want that the afterLast order no should come from database directly and should get display in orderno field and the other details along with the order no should get displayed in database then how to do this. please reply me .
View Answers

January 23, 2010 at 1:29 PM

Hi Friend,

Try the following code:

1)modify.jsp:

<%@ page language="java" import="java.sql.*" %>
<%
Connection con=null;
ResultSet rs=null;
Statement stmt=null;
int No=0;
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con=DriverManager.getConnection("jdbc:odbc:access");
stmt=con.createStatement();
rs=stmt.executeQuery("select TOP 1 OrderNo from OrderTab ORDER BY OrderNo DESC");
while(rs.next())
{
int Ono=rs.getInt(1);
No=Ono+1;
}
}
catch(SQLException se)
{out.println("Database error="+se.getMessage());
}

catch(Exception e)
{out.println("Error="+e.getMessage());
}

%>

<HTML>
<HEAD>
<TITLE> Place Order </TITLE>
<script type="text/javascript">
function checkName(text) {
if(isNaN(text)){ return 1;}
else{alert("Invalid Name! The only charachters accepted are A - Z and a - z");return 0;}
}
function checkPhoneNumber(num) {
if(isNaN(num)){alert("Invalid Phone Number! The only characters permitted are 0 to 9"); return 0;}
else{return 1;}
}

function Validate()
{
var name=document.form.Name;
var phone=document.form.PhoneNo;
var email=document.form.Email;
if(document.form.OrderNo.value=="")
{ alert("Please enter valid OrderNo");
return false;
}
if(name.value=="")
{ alert("Please enter valid Client's Name");
return false;

}
if (checkName(name.value)==false){
name.value="";
name.focus();
return false;
}
if(document.form.Address.value=="")
{ alert("Please enter valid Client's Address");
return false;
}
if(email.value=="")
{ alert("Please enter valid Email Id");
return false;
}
apos=email.value.indexOf("@")
dotpos=email.value.lastIndexOf(".")
if (apos<1 || dotpos-apos<2)
{
alert("Invalid Email Id")
email.value=="";
email.focus();
return false;
}

if(phone.value=="")
{ alert("Please enter valid PhoneNo");
return false;
}
if (checkPhoneNumber(phone.value)==false){
phone.value="";
phone.focus();
return false;
}
return true;
}
</script>
</HEAD>

<BODY BGCOLOR="lightblue">
<marquee behavior="alternate" scrollamount=5 scrolldelay=10>
<h1><font size=4 face="Stroustroup" color="#993355">Advertisement Management System</h1></font></marquee><br>

<hr color="green">

January 23, 2010 at 1:30 PM

continue...

<form name="form" method="post" action="insert.jsp" onsubmit="return Validate();">
<center>
<table>
<tr><td>Order No:</td><td><input type="text" name="OrderNo" size=25 value="<%=No%>"></td></tr>
<tr><td>Name:</td><td><input type=text name="Name" size=25 ></td></tr>
<tr><td>Address:</td><td><textarea name="Address" rows=5 cols=25 size=25></textarea></td></tr>
<tr><td>Email:</td><td><input type=text name="Email" size=25></td></tr>
<tr><td>PhoneNo:</td><td><input type=text name="PhoneNo" size=25></td></tr>
<tr><td><input type=submit name=submit value="InsertOrder"></td><td><input type=reset name=reset value="Reset"></td></tr>
</table>
<a href="http://localhost:8080/ProjectAd/Update.jsp"><b><h4 align=center>Update Orders</h4></b></a>
<a href="http://localhost:8080/ProjectAd/Delete.jsp"><b><h4 align=center>Delete Orders</h4></b></a>
<a href="http://localhost:8080/ProjectAd/View.jsp"><b><h4 align=center>View Orders</h4></b></a>
<a href="http://localhost:8080/ProjectAd/PlaceOrd.jsp"><b><h4 align=center>Back </h4></b></a></p>
<p align=center><a href="http://localhost:8080/ProjectAd/MainPage.html"><img src="images/home_ap.jpg" height=20 width=20>MainPage</a>
</center>
</form>
<hr color="green">
</BODY>
</HTML>

2)insert.jsp:
<%@ page language="java" import="java.sql.*" %>
<%
try{
String no=request.getParameter("OrderNo");
String name=request.getParameter("Name");
String add=request.getParameter("Address");
String email=request.getParameter("Email");
String pno=request.getParameter("PhoneNo");

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection("jdbc:odbc:access");
Statement stmt=con.createStatement();
int i=stmt.executeUpdate("insert into OrderTab values('"+no+"','"+name+"','"+add+"','"+email+"','"+pno+"')");
out.println("Data is inserted successfully.");
}
catch(Exception e){}
%>

Thanks

Ads









Related Tutorials/Questions & Answers:
programming error
programming error  I got an error when i did the following program the prg. is to "select the name from database when the age is given for the respective name" error i got is:SQL exception please give me the solution by providing
error at programming
error at programming  import javax.servlet.http.*; import javax.servlet.*; import java.io.*; import java.sql.*; public class Login extends HttpServlet { public void doPost(HttpServletRequest req,HttpServletResponse res
Advertisements
error at programming
error at programming  import javax.servlet.http.*; import javax.servlet.*; import java.io.*; import java.sql.*; public class Login extends HttpServlet { public void doPost(HttpServletRequest req,HttpServletResponse res
error at programming
error at programming  import javax.servlet.http.*; import javax.servlet.*; import java.io.*; import java.sql.*; public class Login extends HttpServlet { public void doPost(HttpServletRequest req,HttpServletResponse res
error at programming
error at programming  import javax.servlet.http.*; import javax.servlet.*; import java.io.*; import java.sql.*; public class Login extends HttpServlet { public void doPost(HttpServletRequest req,HttpServletResponse res
error at programming
error at programming  import javax.servlet.http.*; import javax.servlet.*; import java.io.*; import java.sql.*; public class Login extends HttpServlet { public void doPost(HttpServletRequest req,HttpServletResponse res
error at programming
error at programming  import javax.servlet.http.*; import javax.servlet.*; import java.io.*; import java.sql.*; public class Login extends HttpServlet { public void doPost(HttpServletRequest req,HttpServletResponse res
error at programming
error at programming  import javax.servlet.http.*; import javax.servlet.*; import java.io.*; import java.sql.*; public class Login extends HttpServlet { public void doPost(HttpServletRequest req,HttpServletResponse res
error at programming
error at programming  import javax.servlet.http.*; import javax.servlet.*; import java.io.*; import java.sql.*; public class Login extends HttpServlet { public void doPost(HttpServletRequest req,HttpServletResponse res
error at programming
error at programming  <p>import javax.servlet.http.*; import javax.servlet.*; import java.io.*; import java.sql.*;</p> <p>public class Login extends HttpServlet { public void doPost(HttpServletRequest
Programming error - JSP-Servlet
Programming error   --%> Place Order function Validate() { var valid=true; if(document.forms.OrderNo.value=="") { alert... where if @ is not given or (dot). is not given etc then it should display error
Programming Error - JSP-Servlet
Programming Error  import java.util.*; import javax.mail.*; import javax.mail.internet.*; public class SendMail { public static void main(String args[]) throws Exception { String host = "192.168.10.205
Programming Error - JSP-Servlet
Programming Error   Place Ad function func() { var filename = document.form.img.value; window.location.href=("http://localhost:8080/ProjectAd/Preview? filename="+filename); } function Draft
Programming
Programming  Given a number n, write a programming to determine its square root if it is possible, in the contraly case print an appropriate massege on the screen
programming
Java Constructor programming for single and double constructor  write a program which have no argument constructor ,single parameter constructor constructor,double parameter constor,and the now when we create a object
Error-
Error-   Hello, I would like to know about XSD file. I try to print XML file but I am getting error SAXException-- says Content is not allowed in prolog. Please help me
error
error  i have 404 error in my program plz tell me yhe solution about
error
error  i have 404 error in my program plz tell me yhe solution about
error
/ServletUserEnquiryForm.shtml getting an error given below SQLException caught: [Microsoft][ODBC SQL Server Driver]COUNT field incorrect or syntax error please suggest
Error
Error  I have created ajax with php for state and city. When I change state then city will not come in dropdown list and it give me error as 'Unknown Runtime Error'. This error come only in IE browser, but in other brower
error
error
error
error  When I deploye the example I have this message cannot Deploy HelloWorld Deployment Error for module: HelloWorld: Error occurred during deployment: Exception while deploying the app [HelloWorld
error!!!!!!!!!
error!!!!!!!!!   st=con.createStatement(); int a=Integer.parseInt(txttrno.getText()); String b=txttname.getText(); String c=txtfrom.getText(); String d=txtto.getText
error!!!!!!!!!
error!!!!!!!!!   st=con.createStatement(); int a=Integer.parseInt(txttrno.getText()); String b=txttname.getText(); String c=txtfrom.getText(); String d=txtto.getText
error!!!!!!!!!
error!!!!!!!!!   st=con.createStatement(); int a=Integer.parseInt(txttrno.getText()); String b=txttname.getText(); String c=txtfrom.getText(); String d=txtto.getText
Error
Error  Hi. I am getting error in the following code after the line I have commented as ERROR. How to solve this. Thanks in advance. package...;"); // ERROR out.println(" var pattern
Error
Error  Hi. I am getting error in the following code after the line I have commented as ERROR. How to solve this. Thanks in advance. package...;"); // ERROR out.println(" var pattern
Error
Error  Hi. I am getting error in the following code after the line I have commented as ERROR. How to solve this. Thanks in advance. package...;"); // ERROR out.println(" var pattern
Error
Error  Hi. I am getting error in the following code after the line I have commented as ERROR. How to solve this. Thanks in advance. package...;"); // ERROR out.println(" var pattern = /^\d{3,5
error
error  whats the error.............. import java.util.Scanner; public class g { public static void main(String[] args) { Scanner s=new Scanner(System.in); int d,x,y; System.out.println("Enter the first number
network programming
network programming   Tutorial for Network programming and administration

Ads