...

View Full Version : Exception occuring in getParameter



venkatgfo
02-04-2008, 03:49 PM
<%@ page contentType="text/html; charset=iso-8859-1" language="java" import="java.sql.*" errorPage="" %>
<%@ page contentType="text/html; charset=iso-8859-1" language="java" import="java.util.*" errorPage="" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Create</title>
</head>
<body>

<%
String tablename=request.getParameter("tablename");
int row=Integer.parseInt(request.getParameter("noofrow"));
out.println(row);
String query=new String();
for(int i=1;i<=row;i++)
{
if(i!=row)
query=query+request.getParameter("att"+i+"")+" "+request.getParameter("d"+i+"")+"("+request.getParameter("size"+i+"")

+")"+",";
else
query=query+request.getParameter("att"+i+"")+" "+request.getParameter("d"+i+"")+"("+""+request.getParameter("size"+i+"")+")";
%>
<%
}
//Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
//Connection con=DriverManager.getConnection("jdbc:odbc:mydsn","scott","tiger");
//Statement st = con.createStatement();
//boolean b = st.execute("create table "+tablename+"("+query+")");
out.println(query);
%>
<h3>Synatx Of SQL Command</h3>
<%
out.println("create table "+" "+tablename+"("+query+")");
%>
</body>
</html>

I'am getting an exception : An exception occurred processing JSP page /create.jsp at line 14

please help me find the error.

sobrien79
02-05-2008, 09:18 PM
Without the error or the exact conditions it would be hard for anyone to debug.

But, one thing I did notice right away:


int row=Integer.parseInt(request.getParameter("noofrow"));

should be:



int row = 0; //you can set this to some default value
try {
row = Integer.parseInt(request.getParameter("noofrow"));
} catch (NumberFormatException nfe) {}


If request.getParameter("noofrow") returns null or something that is not a number, then you are going to have a problem.

venkatgfo
02-10-2008, 09:24 AM
thanks for the reply your right i getting an error as the request.getParameter("noofrow") returns a string. I'am posting both the codes of both the pages.

Pg1.html

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Create</title>
<script>
function add(form)
{
//var form = document.forms[0];
var k= parseInt(form.noofrow.value);
for(var i=1;i<=k;i++)
{
var d= document.getElementById("div");
d.innerHTML+="Attribute"+i+"<input type=text name=att"+i+">";
d.innerHTML+="DataType"+i+"<select name=d"+i+"><option>Number</option><option>VarChar</option><option>VarChar2</option></select>";
d.innerHTML+="Size"+i+"<input type=text name=size"+i+" maxlength=5 size=5><br>";
}
}
</script>
</head>
<body>
<center><h1>Create Table</h1></center>
<form name="f1" method="POST" action="pg2.jsp">
Enter Table Name<input type="text" name="tablename"><br>
<div id="div">
Enter No. Of Values<input type=text name="noofrow" maxlength="20">
<input type="button" value="OK" onclick="add(this.form)" id="button1" name="button1"/><br>
</div>
<input type="submit" value="submit">
</form>
</body>
</html>


pg.2 -- pg2.jsp

<%@page import="java.sql.*" errorPage="" %>
<%@page import="java.util.*" errorPage="" %>
<html>
<head>
<title>Create</title>

</head>
<body>
<%

String tablename=request.getParameter("tablename");
out.println(tablename);
//String row=request.getParameter("noofrow");
int row=0;
try {
int row = Integer.parseInt(request.getParameter("noofrow"));
} catch (NumberFormatException nfe) {}
out.println(row);
String query=new String();
for(int i=1;i<=row;i++)
{
if(i!=row)
query=query+request.getParameter("att"+i+"")+" "+request.getParameter("d"+i+"")+"("+""+request.getParameter("size"+i+"")+")"+",";
else
query=query+request.getParameter("att"+i+"")+" "+request.getParameter("d"+i+"")+"("+""+request.getParameter("size"+i+"")+")";
out.println(query);
%>
<%
}

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection("jdbc:odbc:mydsn","scott","tiger");
Statement st = con.createStatement();
//boolean b = st.execute("create table"+tablename+"("+query+")");
%>
<h3>Synatx Of SQL Command</h3>
<%
out.println("create table "+" "+tablename+"("+query+")");
%>
</body>
</html>


please help me out..



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum