Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Jan 2008
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Exception occuring in getParameter

    Code:
    <%@ 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.

  • #2
    Regular Coder
    Join Date
    Jan 2008
    Location
    Willow Grove, PA
    Posts
    169
    Thanks
    1
    Thanked 27 Times in 27 Posts
    Without the error or the exact conditions it would be hard for anyone to debug.

    But, one thing I did notice right away:

    Code:
    int row=Integer.parseInt(request.getParameter("noofrow"));
    should be:

    Code:
    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.

  • #3
    New to the CF scene
    Join Date
    Jan 2008
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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..


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •