Method edit in class data access cannot be applied to given types

Ayapie Tateyama

I'm running a jsp for the edit function and for some reason, the String idTemp used to parse the int id kept on getting recognized as some data for the update to be executed.

<%@page import="dao.DataAccess"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
    </head>
    <body>
        <%
            String idTemp = request.getParameter("id"); //1
            int id = Integer.parseInt(idTemp); //2            
            String station = request.getParameter("station"); //3
            String date = request.getParameter("date"); //4
            String shift = request.getParameter("shift"); //5
            String uprice = request.getParameter("uprice"); //6
            String cashliters = request.getParameter("cashliters"); //7
            String cashamt = request.getParameter("cashamt"); //8
            String cardliters = request.getParameter("cardliters"); //9
            String cardamt = request.getParameter("cardamt"); //10
            String chargeliters = request.getParameter("chargeliters"); //11
            String chargeamt = request.getParameter("chargeamt"); //12 
            String gcliters = request.getParameter("gcliters"); //13
            String gcamt = request.getParameter("gcamt"); //14
            String fleetliters = request.getParameter("fleetliters"); //15
            String fleetamt = request.getParameter("fleetamt"); //16
            String tappingliters = request.getParameter("tappingliters"); //17
            String tappingamt = request.getParameter("tappingamt"); //18
            String hosefillliters = request.getParameter("hosefillliters"); //19
            String hosefillamt = request.getParameter("hosefillamt"); //20
            String calibrateliters = request.getParameter("calibrateliters"); //21
            String calibrateamt = request.getParameter("calibrateamt"); //22
            String grossliters = request.getParameter("grossliters"); //23
            String grossamt = request.getParameter("grossamt"); //24
            String cashdepoamt = request.getParameter("cashdepoamt"); //25            
            String checkdepoamt = request.getParameter("checkdepoamt"); //26
            String variance = request.getParameter("variance"); //27
            String cashier = request.getParameter("cashier"); //28
            String nooftrans = request.getParameter("nooftrans"); //29
            String tank1level = request.getParameter("tank1level"); //30
            String tank1liters = request.getParameter("tank1liters"); //31
            String tank2level = request.getParameter("tank2level"); //32
            String createdate = request.getParameter("createdate"); //33
            String userid = request.getParameter("userid"); //34
            String transmit = request.getParameter("transmit"); //35
            String transmitdate = request.getParameter("transmitdate"); //36
            String tank2liters = request.getParameter("tank2liters"); //37
            String product = request.getParameter("product"); //38
            
            DataAccess da = new DataAccess();
            da.edit(id, station, date, shift, uprice, cashliters, cashamt, cardliters, cardamt, chargeliters, chargeamt, gcliters, gcamt, fleetliters, fleetamt, tappingliters, tappingamt, hosefillliters, hosefillamt, calibrateliters, calibrateamt, grossliters, grossamt, cashdepoamt, checkdepoamt, variance, cashier, nooftrans, tank1level, tank1liters, tank2level, createdate, userid, transmit, transmitdate, tank2liters, product);
            
            response.sendRedirect("/CRUD_News/AllPost");
        %>
    </body>
</html>

error is on line:

            da.edit(id, station, date, shift, uprice, cashliters, cashamt, cardliters, cardamt, chargeliters, chargeamt, gcliters, gcamt, fleetliters, fleetamt, tappingliters, tappingamt, hosefillliters, hosefillamt, calibrateliters, calibrateamt, grossliters, grossamt, cashdepoamt, checkdepoamt, variance, cashier, nooftrans, tank1level, tank1liters, tank2level, createdate, userid, transmit, transmitdate, tank2liters, product);

The error is:

method edit in class data access cannot be applied to given types
required: int, +37 String
found: int, +36 String
reason: actual and formal argument lists differ in length

What do you suggest I do to keep the idTemp string yet be able to execute without having it in the data to be inserted?

Edit: EditPost.java

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package servlet;

import dao.DataAccess;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 *
 * @author Thang
 */
public class EditPost extends HttpServlet {

    /**
     * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
     * methods.
     *
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
             {
        String idTemp = request.getParameter("id");
        int id = Integer.parseInt(idTemp);
        request.setAttribute("getNewsById", DataAccess.getNewById(id));
        RequestDispatcher rd = request.getRequestDispatcher("EditPost.jsp");
        try {
            rd.forward(request, response);
        } catch (ServletException | IOException ex) {
            Logger.getLogger(EditPost.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
    /**
     * Handles the HTTP <code>GET</code> method.
     *
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        processRequest(request, response);
    }

    /**
     * Handles the HTTP <code>POST</code> method.
     *
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        processRequest(request, response);
    }

    /**
     * Returns a short description of the servlet.
     *
     * @return a String containing servlet description
     */
    @Override
    public String getServletInfo() {
        return "Short description";
    }// </editor-fold>

}

DataAccess.java

    public void edit(int id, String station, String description, String date, String shift, String uprice, String cashliters, String cashamt, String cardliters, String cardamt, String chargeliters, String chargeamt, String gcliters, String gcamt, String fleetliters, String fleetamt, String tappingliters, String tappingamt, String hosefillliters, String hosefillamt, String calibrateliters, String calibrateamt, String grossliters, String grossamt, String cashdepoamt, String checkdepoamt, String variance, String cashier, String nooftrans, String tank1level, String tank1liters, String tank2level, String createdate, String userid, String transmit, String transmitdate, String tank2liters, String product){
        try {
            String sql = "update DailySales SET dsStnCode = ?, dsDate = ?, dsShift = ?, dsUPrice = ?, dsCashLiters = ?, dsCashAmt = ?, dsCardLiters = ?, dsCardAmt = ?, dsChargeLiters = ?, dsChargeAmt = ?, dsGCLiters = ?, dsGCAmt = ?, dsFleetLiters = ?, dsFleetAmt = ?, dsTappingLiters = ?, dsTappingAmt = ?, dsHosefillLiters = ?, dsHoseFillAmt = ?, dsCalibrateLiters = ?, dsCalibrateAmt = ?, dsGrossLiters = ?, dsGrossAmt = ?, dsCashDepoAmt = ?, dsCheckDepoAmt = ?, dsVariance = ?, dsCashier = ?, dsNoOfTrans = ?, dsTank1Level = ?, dsTank1Liters = ?, dsTank2Level = ?, dsCreateDate = ?, dsUserID = ?, dsTransmit = ?, dsTransmitDate = ?, dsTank2Liters = ?, dsProduct = ?" + " where id = ?";

            PreparedStatement ps= DBUtils.getPreparedStatement(sql);
            ps.setString(1, station);
            ps.setString(2, date);
            ps.setString(3, shift);
            ps.setString(4, uprice);
            ps.setString(5, cashliters);
            ps.setString(6, cashamt);
            ps.setString(7, cardliters);            
            ps.setString(8, cardamt);
            ps.setString(9, chargeliters);
            ps.setString(10, chargeamt);
            ps.setString(11, gcliters);
            ps.setString(12, gcamt);
            ps.setString(13, fleetliters);
            ps.setString(14, fleetamt);
            ps.setString(15, tappingliters);
            ps.setString(16, tappingamt);
            ps.setString(17, hosefillliters);
            ps.setString(18, hosefillamt);
            ps.setString(19, calibrateliters);
            ps.setString(20, calibrateamt);
            ps.setString(21, grossliters);
            ps.setString(22, grossamt);
            ps.setString(23, cashdepoamt);
            ps.setString(24, checkdepoamt);
            ps.setString(25, variance);
            ps.setString(26, cashier);
            ps.setString(27, nooftrans);
            ps.setString(28, tank1level);
            ps.setString(29, tank1liters);
            ps.setString(30, tank2level);
            ps.setString(31, createdate);
            ps.setString(32, userid);
            ps.setString(33, transmit);
            ps.setString(34, transmitdate);
            ps.setString(35, tank2liters);
            ps.setString(36, product);             
            ps.setInt(37, id);
            ps.executeUpdate();
        } catch (ClassNotFoundException | SQLException ex) {
            Logger.getLogger(DataAccess.class.getName()).log(Level.SEVERE, null, ex);
        }
        
    }

EditPost.jsp

<%-- 
    Document   : EditPost
    Created on : Aug 8, 2015, 11:08:34 PM
    Author     : Thang
--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Edit</title>
    </head>
    <body>
        <h1>Edit News</h1>
        <div style="width: 900px; margin-left: auto; margin-right: auto">
            <c:forEach items="${getNewsById}" var="p">
            <form action="JSP/ManagerEditPost.jsp" method="post">                
                <input type="hidden" name="id" value="${p.id}">
                Station:
                <input type="text" name="station" value="${p.station}" style="width: 200px" value="South Area Auto Gas Corp. - Kawit" readonly><br><br>
                <!--Title:<br>
                <input type="text" name="title" style="width: 200px" ><br>
                -->
                Date:
                <input type="date" value="${p.date}" name="date" style="width: 200px"><br><br>
                <!--Description:<br>
                <input type="text" name="description" style="width: 200px"><br>
                -->
                Shift: 
                <select name="shift">
                    <option value="${p.shift}">${p.shift}</option>
                    <option value="GY">GY</option>
                    <option value="AM">AM</option>
                    <option value="PM">PM</option>
                </select><br><br>                  
                Product: 
                <select name="product">
                    <option value="${p.product}">${p.product}</option>                    
                    <option value="LPG">LPG</option>
                    <option value="Diesel">Diesel</option>
                    <option value="Unleaded">Unleaded</option>
                    <option value="Premium">Premium</option>                    
                </select><br><br>
                U/Price:
                <input type="text" value="${p.uprice}" name="uprice" style="width: 200px">
                No. of Transaction:
                <input type="text" value="${p.nooftrans}" name="nooftrans" style="width: 50px"><br><br>
                Cashier:
                <input type="text" value="${p.cashier}" name="cashier" style="width: 300px"><br><br>
                Tank 1:
                <input type="text" value="${p.tank1level}" name="tank1level" placeholder="gauge" style="width: 50px">
                <input type="text" value="${p.tank1liters}" name="tank1liters" placeholder="liters" style="width: 50px"><br><br>
                Tank 2:
                <input type="text" value="${p.tank2level}" name="tank2level" placeholder="gauge" style="width: 50px">
                <input type="text" value="${p.tank2liters}" name="tank2liters" placeholder="liters" style="width: 50px"><br><br><br><br>
                <table>
                    <tr>
                        <td>Description</td>
                        <td>Liters</td>
                        <td>Amount</td>
                    </tr>
                    <tr>
                        <td>Cash:</td>
                        <td><input type="text" value="${p.cashliters}" name="cashliters" placeholder="liters" style="width: 50px"><br></td>
                        <td><input type="text" value="${p.cashamt}" name="cashamt" placeholder="amount" style="width: 100px"><br></td>
                    </tr>
                    <tr>
                        <td>Card:</td>
                        <td><input type="text" value="${p.cardliters}" name="cardliters" placeholder="liters" style="width: 50px"><br></td>
                    <td><input type="text" value="${p.cardamt}" name="cardamt" placeholder="amount" style="width: 100px"><br></td>
                    </tr>
                    <tr>
                        <td>Charge:</td>
                        <td><input type="text" value="${p.chargeliters}" name="chargeliters" placeholder="liters" style="width: 50px"><br></td>
                    <td><input type="text" value="${p.chargeamt}" name="chargeamt" placeholder="amount" style="width: 100px"><br></td>
                    </tr>
                    <tr>
                        <td>G.C:</td>
                        <td><input type="text" value="${p.gcliters}" name="gcliters" placeholder="liters" style="width: 50px"><br></td>
                        <td><input type="text" value="${p.gcamt}" name="gcamt" placeholder="amount" style="width: 100px"><br></td>
                    </tr>
                    <tr>
                        <td>Fleet Card:</td>
                        <td><input type="text" value="${p.fleetliters}" name="fleetliters" placeholder="liters" style="width: 50px"><br></td>
                        <td><input type="text" value="${p.fleetamt}" name="fleetamt" placeholder="amount" style="width: 100px"><br></td>
                    </tr>
                    <tr>
                        <td>Tapping:</td>
                        <td><input type="text" value="${p.tappingliters}" name="tappingliters" placeholder="liters" style="width: 50px"><br></td>
                        <td><input type="text" value="${p.tappingamt}" name="tappingamt" placeholder="amount" style="width: 100px"><br></td>
                    </tr>
                    <tr>
                        <td>Hosefill:</td>
                        <td><input type="text" value="${p.hosefillliters}" name="hosefillliters" placeholder="liters" style="width: 50px"><br></td>
                        <td><input type="text" value="${p.hosefillamt}" name="hosefillamt" placeholder="amount" style="width: 100px"><br></td>
                    </tr>
                    <tr>
                        <td>Calibration: </td>
                        <td><input type="text" value="${p.calibrateliters}" name="calibrateliters" placeholder="liters" style="width: 50px"><br></td>
                        <td><input type="text" value="${p.calibrateamt}" name="calibrateamt" placeholder="amount" style="width: 100px"><br></td>
                    </tr>
                    <tr>
                        <td>Gross: </td>
                        <td><input type="text" value="${p.grossliters}" name="grossliters" placeholder="liters" style="width: 50px"><br></td>
                        <td><input type="text" value="${p.grossamt}" name="grossamt" placeholder="amount" style="width: 100px"><br></td>
                    </tr>                     
                </table>
                
                <br><br>
                Deposit Amount:<br>
                <input type="text" value="${p.cashdepoamt}" name="cashdepoamt" placeholder="gauge" style="width: 100px">
                <input type="text" value="${p.checkdepoamt}" name="checkdepoamt" placeholder="liters" style="width: 100px">
                <input type="text" value="${p.variance}" name="variance" placeholder="liters" style="width: 100px"><br><br>

                <!--
                START NOTE: ADD TO EDIT LATER
                -->
                User ID:
                <input type="text" value="${p.userid}" name="userid" style="width: 300px"><br><br>
                Transmit
                <input type="text" value="${p.transmit}" name="transmit" style="width: 300px"><br><br>
                Transmit Date:
                <input type="date" value="${p.transmitdate}" name="transmitdate" style="width: 300px"><br><br>
                Create Date:
                <input type="date" value="${p.createdate}" name="createdate" style="width: 300px"><br><br>

                
                <!--
                NOTE: ADD TO EDIT LATER
                -->
                
                <!--Detail:<br>
                <textarea name="detail" style="width: 400px; height: 200px"></textarea><br>
                -->
                <!--
                Category: 
                <select name="category">
                    <option value="World">World</option>
                    <option value="Tech">Tech</option>
                    <option value="Sport">Sport</option>
                </select><br>
                -->
                <!--Image:<br>
                <input type="text" name="image" style="width: 200px"><br>
                -->
                <br><br><input type="submit" value="Submit">
            </form>
            </c:forEach>

        </div>
    </body>
</html>

Viraj Nalawade
  1. First of all avoid the method with so many parameters. Some reasons here for that.
  2. dont write java code in JSP

  3. You are missing String description parameter.

The number of parameters are different.
Required number of parameters for DataAccess classes edit method are 37.
You are passing 36. You need to call the method according to its signature ie according to number and type of parameter.

The name of the parameter you are missing is String description .

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Issue with "Method in Class cannot be applied to given types"

From Dev

Issue with "Method in Class cannot be applied to given types"

From Dev

error: method addOutcome in class OutcomesTable cannot be applied to given types

From Dev

method in class cannot be applied to given types; required: HashMap<String,Integer>

From Dev

How to fix method cannot be applied to given types

From Dev

Constructor in class cannot be applied to given types

From Dev

java constructor in class cannot be applied to given types

From Dev

Constructor in class cannot be applied to given types

From Dev

Error: method in class cannot be applied to given type

From Dev

Play Framework 2.2.1 - Compilation error: "method render in class index cannot be applied to given types;"

From Dev

How to resolve the Android error "method setSupportActionBar in class AppCompatActivity cannot be applied to given types"?

From Dev

Java beginners coding error - method contains in class String cannot be applied to given types

From Dev

Method cannot be applied to given types. Hope for assistance

From Dev

Method cannot be applied to given types. Hope for assistance

From Dev

Constructor in class cannot be applied to given types. Hope for assistance

From Dev

Error: Constructor Room in class Room cannot be applied to given types

From Dev

Java error: constructor in class cannot be applied to given types

From Dev

"constructor JSONParser in class JSONParser cannot be applied to given types" error occured

From Dev

Android: constructor ContactsAdapter in class ContactsAdapter cannot be applied to given types

From Dev

constructor in class cannot be applied to given types android studio

From Dev

Constructor in class cannot be applied to given types. Hope for assistance

From Dev

java: constructor ranngeIpScanner in class cannot be applied to given types;

From Dev

new BufferedReader in class Files cannot be applied to given types

From Dev

Why does javac emit "error: method in class cannot be applied to given types" when an instance method is used in a static context?

From Dev

Constructor cannot be applied to given types?

From Dev

Construtor cannot be applied to given types

From Dev

Method cannot be applied to given type

From Dev

Java - error: constructor "constructor name" in class "class name" cannot be applied to given types;

From Dev

"Cannot be applied to given types" Error during PrintStream

Related Related

  1. 1

    Issue with "Method in Class cannot be applied to given types"

  2. 2

    Issue with "Method in Class cannot be applied to given types"

  3. 3

    error: method addOutcome in class OutcomesTable cannot be applied to given types

  4. 4

    method in class cannot be applied to given types; required: HashMap<String,Integer>

  5. 5

    How to fix method cannot be applied to given types

  6. 6

    Constructor in class cannot be applied to given types

  7. 7

    java constructor in class cannot be applied to given types

  8. 8

    Constructor in class cannot be applied to given types

  9. 9

    Error: method in class cannot be applied to given type

  10. 10

    Play Framework 2.2.1 - Compilation error: "method render in class index cannot be applied to given types;"

  11. 11

    How to resolve the Android error "method setSupportActionBar in class AppCompatActivity cannot be applied to given types"?

  12. 12

    Java beginners coding error - method contains in class String cannot be applied to given types

  13. 13

    Method cannot be applied to given types. Hope for assistance

  14. 14

    Method cannot be applied to given types. Hope for assistance

  15. 15

    Constructor in class cannot be applied to given types. Hope for assistance

  16. 16

    Error: Constructor Room in class Room cannot be applied to given types

  17. 17

    Java error: constructor in class cannot be applied to given types

  18. 18

    "constructor JSONParser in class JSONParser cannot be applied to given types" error occured

  19. 19

    Android: constructor ContactsAdapter in class ContactsAdapter cannot be applied to given types

  20. 20

    constructor in class cannot be applied to given types android studio

  21. 21

    Constructor in class cannot be applied to given types. Hope for assistance

  22. 22

    java: constructor ranngeIpScanner in class cannot be applied to given types;

  23. 23

    new BufferedReader in class Files cannot be applied to given types

  24. 24

    Why does javac emit "error: method in class cannot be applied to given types" when an instance method is used in a static context?

  25. 25

    Constructor cannot be applied to given types?

  26. 26

    Construtor cannot be applied to given types

  27. 27

    Method cannot be applied to given type

  28. 28

    Java - error: constructor "constructor name" in class "class name" cannot be applied to given types;

  29. 29

    "Cannot be applied to given types" Error during PrintStream

HotTag

Archive