我使用spring jdbc,并且想执行sql语句插入。我有以下java类
@Repository
public interface MaquinistaCentroGestionRepository extends BcmCustomRepository<MaquinistaCentroGestionBean>, MaquinistaCentroGestionFiltrosRepository {
@Query("insert into mer_centro_gestion_maq(id_centro, nombre, activo) values (:idcentro, :nombrecentro, :activo)")
int createCentroGestion(String idcentro, String nombrecentro, String activo);
}
MaquinistaCentroGestionFiltrosRepository类是
@Repository
public class MaquinistaCentroGestionFiltrosRepositoryImpl implements MaquinistaCentroGestionFiltrosRepository{
@Autowired
private @Qualifier("oracleJdbcTemplate" ) NamedParameterJdbcOperations template;
private BeanPropertyRowMapper<MaquinistaCentroGestionBean> rowMapper = new BeanPropertyRowMapper<>(MaquinistaCentroGestionBean.class);
当我调用方法
int createCentroGestion(String idcentro, String nombrecentro, String activo);
我收到以下错误
019-09-12 12:53:18 DEBUG org.springframework.jdbc.core.JdbcTemplate - Executing prepared SQL statement [insert into mer_centro_gestion_maq(id_centro, nombre, activo) values (?, ?, ?)]
2019-09-12 12:53:18 TRACE org.springframework.jdbc.core.StatementCreatorUtils - Setting SQL statement parameter value: column index 1, parameter value [1], value class [java.lang.String], SQL type unknown
2019-09-12 12:53:18 TRACE org.springframework.jdbc.core.StatementCreatorUtils - Setting SQL statement parameter value: column index 2, parameter value [centro 3], value class [java.lang.String], SQL type unknown
2019-09-12 12:53:18 TRACE org.springframework.jdbc.core.StatementCreatorUtils - Setting SQL statement parameter value: column index 3, parameter value [0], value class [java.lang.String], SQL type unknown
2019-09-12 12:53:18 ERROR com.renfe.bcm.aspect.BcmAspect - Error en RestController: execution(int com.renfe.bcm.maquinista.centrogestion.restcontroller.MaquinistaCentroGestionController.createCentroGestion(String,String,String))
org.springframework.jdbc.IncorrectResultSetColumnCountException: Incorrect column count: expected 1, actual 0
at org.springframework.jdbc.core.SingleColumnRowMapper.mapRow(SingleColumnRowMapper.java:110)
at org.springframework.jdbc.core.RowMapperResultSetExtractor.extractData(RowMapperResultSetExtractor.java:94)
at org.springframework.jdbc.core.RowMapperResultSetExtractor.extractData(RowMapperResultSetExtractor.java:61)
at org.springframework.jdbc.core.JdbcTemplate$1.doInPreparedStatement(JdbcTemplate.java:679)
at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:617)
at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:669)
at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:694)
at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:748)
at org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate.queryForObject(NamedParameterJdbcTemplate.java:232)
at com.renfe.bcm.config.bbdd.bean.BcmNamedParameterJdbcTemplate.queryForObject(BcmNamedParameterJdbcTemplate.java:40)
如何使用oracleJdbcTemplate和语句插入?