我尝试在存储过程中传达汽车列表,但是我收到错误。
我上课了:
public class Car {
private final int id;
private final String mark;
public ProviderVirtualCondition(
@JsonProperty("id") int id,
@JsonProperty("mark") String mark) {
this.id = id;
this.mark = mark;
}
}
程序:
create or replace PACKAGE Cars AS
TYPE car_array IS TABLE OF CAR%ROWTYPE;
PROCEDURE updateCars(cars in car_array);
END Cars;
create or replace PACKAGE BODY Cars AS
PROCEDURE updateCars(cars in car_array) AS
BEGIN
INSERT INTO car (id, mark) VALUES (cars(1).id, cars(1).mark);
END updateCars;
END Cars;
我想在DB中插入Car对象列表。我这样做:
List<Car> cars = new ArrayList<Car>();
cars.add(new Car(1, "Honda"));
SqlParameterSource in = new MapSqlParameterSource().addValue(
"cars",
cars
);
updateCars().execute(in);
在updateCars()中:
String carsTypeName = format("%s.%s.%s", schema, PACKAGE, "car_array");
return new SimpleJdbcCall(jdbcTemplate)
.withCatalogName(PACKAGE)
.withoutProcedureColumnMetaDataAccess()
.withProcedureName("updateCars")
.withSchemaName(schema)
.declareParameters(new SqlParameter("cars", Types.ARRAY, carsTypeName));
得到:
java.sql.SQLException: Fail to convert to internal representation: [....Car@60c94c7f]
如何解决?
我使用https://coderanch.com/t/589556/framework/Calling-Stored-Procedure-list-values
中的代码解析它