Функция вызова JDBC с параметром пользовательского типаJAVA

Программисты JAVA общаются здесь
Гость
Функция вызова JDBC с параметром пользовательского типа

Сообщение Гость »

У меня есть собственный тип Postgres, как показано ниже:

Код: Выделить всё

create type custom_type as
(
a  text,
b   text,
c boolean
);
И функция следующая

Код: Выделить всё

CREATE OR REPLACE FUNCTION test(strings custom_type[]) RETURNS VOID
AS
$$
BEGIN

end;
$$ language plpgsql;
Теперь у меня есть следующая реализация JDBC.

Код: Выделить всё

try (Connection connection = DataSource.getConnection()) {

String call = "select test(?)";

Array sqlArray = connection.createArrayOf("custom_type", new CustomTypeDTO[]{
new CustomTypeDTO("123456", "11221", "false"),
new CustomTypeDTO("123426", "113221", "false"),
});

PreparedStatement preparedStatement = connection.prepareStatement(call)
preparedStatement.setArray(1, sqlArray);
preparedStatement.execute();
} catch (SQLException e) {
e.printStackTrace();
}
Здесь я получаю следующую ошибку
ОШИБКА: неверный литерал записи: "main.java.test.dto.CustomTypeDTO@4802796d"
Подробно: отсутствует левая скобка.

Подробнее здесь: https://stackoverflow.com/questions/781 ... -parameter

Вернуться в «JAVA»