Hi Friends I have just started learning Java.I am getting a problem may be a small one but i coundn't able to figure it out.so here is my Servlet code iam trying to insert data into database after submitting form iam getting java.lang.NumberFormatException: For input string: ""
I want to know how to check user entered String instead of Int ??
String Name=request.getParameter("name");
String Password=request.getParameter("pass");
int Mobile= Integer.parseInt(request.getParameter("mobile"));
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection("Jdbc:Odbc:trans","sa","disil");
PreparedStatement ps=con.prepareStatement("insert into truck values(?,?,?)");
ps.setString(1,Name);
ps.setString(2,Password);
ps.setInt(3,Mobile);
int i=ps.executeUpdate();
if(Name.equals(""))
{
request.setAttribute("ErrorN", "Cannot Leave Empty");
}
if(Password.equals(""))
{
request.setAttribute("ErrorP", "Cannot Leave Empty");
}
if(Mobile==0)
{
request.setAttribute("ErrorM", "Cannot Leave Empty");
}
if(i==1)
{
RequestDispatcher d=request.getRequestDispatcher("manager.jsp");
d.forward(request, response);
}
else
{
request.setAttribute( "truckerr","Please Try Again");
}
}