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
    Rep Power

    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);
    stmt = connection.createStatement();
    int update_count = stmt.executeUpdate("INSERT INTO APP.CUSTOMERINFO (CUSTOMERID,CUSTOMERNAME,SHIPPINGADDRESS) " +" VALUES("+ IDNum + ", '" + Name + "', '" + Address + "')");
    catch (SQLException e)
    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 Forum Police
    Join Date
    Sep 2008
    Madgaon, Goa, India
    Rep Power

    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.

    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, 04:56 AM
  2. simple code not compiling
    By cliffh in forum New To Java
    Replies: 8
    Last Post: 09-30-2010, 06:47 AM
  3. my code compiling but not running
    By girishkumar in forum New To Java
    Replies: 16
    Last Post: 03-16-2010, 05: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, 09:33 AM
  5. Trouble compiling code
    By waelhelbawi in forum New To Java
    Replies: 1
    Last Post: 05-12-2008, 05: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