Spring报错: Unable to determine the correct call signature

本文介绍了一个Spring框架中使用JDBC调用存储过程时出现的问题及异常堆栈。在尝试获取特定ID的学生记录时,由于未能正确确定存储过程签名而导致了InvalidDataAccessApiUsageException异常。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Spring 中 SQL 的存储过程

在运行MainApp时报错:

--------记录列表--------
ID:1,Name黑熊,Age11
ID:2,Name加菲猫,Age13
ID:3,Name阿丽,Age15
--------ID为2的记录信息--------
Exception in thread "main" org.springframework.dao.InvalidDataAccessApiUsageException: 
Unable to determine the correct call signature - no procedure/function/signature for 'getrecord'
    at org.springframework.jdbc.core.metadata.GenericCallMetaDataProvider.processProcedureColumns(GenericCallMetaDataProvider.java:347)
    at org.springframework.jdbc.core.metadata.GenericCallMetaDataProvider.initializeWithProcedureColumnMetaData(GenericCallMetaDataProvider.java:112)
    at org.springframework.jdbc.core.metadata.CallMetaDataProviderFactory$1.processMetaData(CallMetaDataProviderFactory.java:133)
    at org.springframework.jdbc.support.JdbcUtils.extractDatabaseMetaData(JdbcUtils.java:336)
    at org.springframework.jdbc.core.metadata.CallMetaDataProviderFactory.createMetaDataProvider(CallMetaDataProviderFactory.java:73)
    at org.springframework.jdbc.core.metadata.CallMetaDataContext.initializeMetaData(CallMetaDataContext.java:242)
    at org.springframework.jdbc.core.simple.AbstractJdbcCall.compileInternal(AbstractJdbcCall.java:303)
    at org.springframework.jdbc.core.simple.AbstractJdbcCall.compile(AbstractJdbcCall.java:288)
    at org.springframework.jdbc.core.simple.AbstractJdbcCall.checkCompiled(AbstractJdbcCall.java:348)
    at org.springframework.jdbc.core.simple.AbstractJdbcCall.doExecute(AbstractJdbcCall.java:363)
    at org.springframework.jdbc.core.simple.SimpleJdbcCall.execute(SimpleJdbcCall.java:198)
    at com.joey.JdbcCall.StudentJDBCTemplate.getStudent(StudentJDBCTemplate.java:37)
    at com.joey.JdbcCall.MainApp.main(MainApp.java:27)


MainApp.java

package com.joey.JdbcCall;

import java.util.List;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class MainApp {

    public static void main(String[] args) {

        ApplicationContext context = new ClassPathXmlApplicationContext("jdbcCallBeans.xml");
        StudentJDBCTemplate studentJDBCTemplate = (StudentJDBCTemplate) context.getBean("studentJDBCTemplate");
        
        /*System.out.println("--------添加记录--------");
        studentJDBCTemplate.create("黑熊", 11);
        studentJDBCTemplate.create("加菲猫", 13);
        studentJDBCTemplate.create("阿丽", 15);*/
        System.out.println("--------记录列表--------");
        List<Student> students=studentJDBCTemplate.listStudent();
        for (Student student : students) {
            System.out.print("ID:"+student.getId());
            System.out.print(",Name"+student.getName());
            System.out.println(",Age"+student.getAge());
        }
        System.out.println("--------ID为2的记录信息--------");
        Student student=studentJDBCTemplate.getStudent(2);
        System.out.print("ID:"+student.getId());
        System.out.print(",Name"+student.getName());
        System.out.println(",Age"+student.getAge());
    }
}

StudentJDBCTemplate.java
package com.joey.JdbcCall;

import java.util.List;
import java.util.Map;
import javax.sql.DataSource;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
import org.springframework.jdbc.core.namedparam.SqlParameterSource;
import org.springframework.jdbc.core.simple.SimpleJdbcCall;

public class StudentJDBCTemplate implements StudentDAO{
    private DataSource dataSource;
    private SimpleJdbcCall jdbcCall;
    
    @Override
    public void setDataSource(DataSource dataSource) {
        this.dataSource=dataSource;
        this.jdbcCall=new SimpleJdbcCall(dataSource)
                .withProcedureName("getRecord");
    }

    @Override
    public void create(String name, Integer age) {
        JdbcTemplate jdbcTemplateObject=new JdbcTemplate(dataSource);
        String SQL="insert into Student(name,age) values(?,?)";
        jdbcTemplateObject.update(SQL,name,age);
        System.out.println("Created Record Name = "+name+" Age = "+age);
        return;
    }

    @Override
    public Student getStudent(Integer id) {
        SqlParameterSource in=new MapSqlParameterSource().addValue("in_id", id);
        Map<String, Object>out=jdbcCall.execute(in);
        Student student = new Student();
        student.setId(id);
        student.setName((String) out.get("out_name"));
        student.setAge((Integer) out.get("out_age"));
        return student;
    }

    @Override
    public List<Student> listStudent() {
        JdbcTemplate jdbcTemplateObject=new JdbcTemplate(dataSource);
        String SQL="select * from Student";
        List<Student> students=jdbcTemplateObject.query(SQL,new StudentMapper());
        return students;
    }
}

完~

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值