Results 1 to 2 of 2
Like Tree1Likes
  • 1 Post By DarrylBurke

Thread: Plz help for some reason this code is not compiling

  1. #1
    webslinger55 is offline Member
    Join Date
    Jan 2012
    Posts
    1
    Rep Power
    0

    Default Plz help for some reason this code is not compiling

    I am trying to parse an Integer to put it into a NUMERIC value into a database form a webpage using a servlet in Netbeans. The problem is that when I am parsing it I keep getting the error cannot put a CHAR into a NUMERIC value can someone please tell me what I am doing wrong here is my code.
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
    processRequest(request, response);
    String ID = request.getParameter("ID");
    int IDNum = Integer.parseInt(ID);
    try
    {
    stmt = connection.createStatement();
    int update_count = stmt.executeUpdate("INSERT INTO APP.CUSTOMERINFO (CUSTOMERID,CUSTOMERNAME,SHIPPINGADDRESS) " +" VALUES("+ IDNum + ", '" + Name + "', '" + Address + "')");
    stmt.close();
    }
    catch (SQLException e)
    {
    e.printStackTrace();
    }
    }
    and this is the error.
    SEVERE: java.sql.SQLSyntaxErrorException: Columns of type 'NUMERIC' cannot hold values of type 'CHAR'.
    Please this is driving me insane.

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,193
    Rep Power
    19

    Default Re: Plz help for some reason this code is not compiling

    First off, your code is fragile and prone to SQL injection. Use PreparedStatement, not Statement.

    That should solve the problem you're facing, too.

    And as there's nothing NetBeans-specific about the question, I'm moving it to JDBC.

    db
    Tolls likes this.
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

Similar Threads

  1. Code stops for no reason
    By Bagzli in forum New To Java
    Replies: 9
    Last Post: 03-03-2011, 03:56 AM
  2. simple code not compiling
    By cliffh in forum New To Java
    Replies: 8
    Last Post: 09-30-2010, 05:47 AM
  3. my code compiling but not running
    By girishkumar in forum New To Java
    Replies: 16
    Last Post: 03-16-2010, 04:45 PM
  4. Help me out in compiling the source code
    By aks.nitw in forum Advanced Java
    Replies: 3
    Last Post: 10-17-2008, 08:33 AM
  5. Trouble compiling code
    By waelhelbawi in forum New To Java
    Replies: 1
    Last Post: 05-12-2008, 04:25 AM

Posting Permissions

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