0

i've created a mysql stored procedure with SP name: spAssignPairNo

my stored procedure doesn't take any parameters and doesn't return any result.

the SP will make data update to Picking_Item table when called.

my question is how can I execute the SP from java spring boot.

i'm very new to java spring boot and in my spring boot program, i've built model.entity and server.repository for Picking_Item.

in my PickingItem.java of model.entity, i've created the following:

@Entity
/*newly added for confusion matrix stored procedure */
@NamedStoredProcedureQuery(name = "PickingItem.spAssignPairNo", 
procedureName = "spAssignPairNo")
@Table(name="picking_item")
@lombok.Data
public class PickingItem implements Serializable
{

in my PickingItemRepository.java of server.Repository, i've created the following:

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
import org.springframework.data.jpa.repository.query.Procedure;


@Repository
public interface PickingItemRepository extends 
JpaRepository<PickingItem,Integer>
{
List<PickingItem> findByPickingOrderId(Integer pickingOrderId); 
Optional<PickingItem> findByPickingOrderIdAndMaterialId(Integer 
pickingOrderId, Integer materialId); 

@Procedure
static boolean spAssignPairNo() {
    // TODO Auto-generated method stub
    return true;
}
}

In server.service's PickingOrderService.java:

public void spAssignPairNoExplicit() {
    try {
        PickingItemRepository.spAssignPairNo();
    } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}

appreciate if anyone can give some hints.

2
  • 2
    Execute it like any other statement which does not produce output.
    – Akina
    Commented Jul 6, 2022 at 9:43
  • do i need to input anything to // TODO Auto-generated method stub * section? Commented Jul 7, 2022 at 5:57

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.