Spring Boot JDBC : call Oracle function
bonjour ,
je suis nouveau avec spring boot.
Je souhaite créer un service web qui fait appel à une fonction pl/sql via JDBCtemplate. J'ai eu cette erreur :
Citation:
java.sql.SQLException: ORA-06550: Ligne 1, colonne 13 :
PLS-00306: wrong number or types of arguments in call to 'LOGINBYALAS'
ORA-06550: Ligne 1, colonne 7 :
PL/SQL: Statement ignored
fonction pl/slq :
Code:
1 2 3 4 5 6 7 8 9 10
| CREATE OR REPLACE FUNCTION LOGINBYALAS (p_user IN VARCHAR2) RETURN VARCHAR2
IS
Res VARCHAR2(1000) ;
BEGIN
If p_user ='ALAS'
THEN Res := 'Hello '|| p_user;
end if;
RETURN Res;
END; |
class Dao
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
| public class LoginDao {
private SimpleJdbcCall simpleJdbcCall;
@Autowired
public void setDataSource(DataSource dataSource) {
JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
jdbcTemplate.setResultsMapCaseInsensitive(true);
this.simpleJdbcCall = new
SimpleJdbcCall(jdbcTemplate).withFunctionName("LOGINBYALAS");
}
public String getLoginRes(String p_user){
SqlParameterSource in = new MapSqlParameterSource().addValue("p_user", p_user);
String Res = simpleJdbcCall.executeFunction(String.class, in);
return Res;
}
} |
class controller
Code:
1 2 3 4 5 6 7 8 9 10 11 12
| @RestController
public class LoginController {
@Autowired
LoginDao login ;
@RequestMapping(value = "/Login/{User}", method = RequestMethod.GET)
public String Login(@PathVariable("User") String p_user )
{
return login.getLoginRes(p_user);
}
} |
merci