2011-10-17 1 views
1

J'ai des problèmes pour appeler la procédure dans le serveur mssql en utilisant java. Je continue de recevoir org.springframework.jdbc.BadSqlGrammarExceptionParamètre non transmis à la procédure

Voici mon code:

public void init(@Qualifier("mssqlDataSource") DataSource dataSource) { 
     JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource); 
     jdbcTemplate.setResultsMapCaseInsensitive(true); 
     this.findBgNumber = new SimpleJdbcCall(jdbcTemplate) 
      .withProcedureName(".sp_GetMaybeBGnumberKT") 
      .withCatalogName("dbVilluleit") 
      .declareParameters(new SqlParameter("@KT", java.sql.Types.VARCHAR)) 
      .returningResultSet("bgNumber", new BgRowMapper()); 
    } 

    public List<BgcNumber> getBGNumber(String kennitala) { 
     SqlParameterSource in = new MapSqlParameterSource() 
     .addValue("@KT", kennitala, java.sql.Types.VARCHAR); 
     Map<String, Object> results = findBgNumber.execute(in); 
     List<BgcNumber> list = (List<BgcNumber>) results.get("bgNumber"); 
     return list; 
    } 

Le stacktrace dit que '@KT' est pas fourni, mais qui ne va pas.

Une idée de ce que je fais mal ici?

C'est le stacktrace

org.springframework.jdbc.BadSqlGrammarException: CallableStatementCallback; bad SQL grammar [{call dbVilluleit..sp_GetMaybeBGnumberKT()}]; nested exception is com.microsoft.sqlserver.jdbc.SQLServerException: Procedure or function 'sp_GetMaybeBGnumberKT' expects parameter '@KT', which was not supplied. 
at org.springframework.jdbc.support.SQLStateSQLExceptionTranslator.doTranslate(SQLStateSQLExceptionTranslator.java:97) 
at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:72) 
at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:80) 
at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:80) 
at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:952) 
at org.springframework.jdbc.core.JdbcTemplate.call(JdbcTemplate.java:985) 
at org.springframework.jdbc.core.simple.AbstractJdbcCall.executeCallInternal(AbstractJdbcCall.java:368) 
at org.springframework.jdbc.core.simple.AbstractJdbcCall.doExecute(AbstractJdbcCall.java:342) 
at org.springframework.jdbc.core.simple.SimpleJdbcCall.execute(SimpleJdbcCall.java:164) 
at is.siminn.centrex.data.BgcDataGatewayImpl.getBGNumber(BgcDataGatewayImpl.java:73) 
at is.siminn.centrex.service.BgcInfoServiceImpl.getBgcInfo(BgcInfoServiceImpl.java:55) 
at is.siminn.centrex.ws.BgcImpl.getBgc(BgcImpl.java:30) 
at is.siminn.centrex.ws.BgcTestInt.testGetBGC(BgcTestInt.java:36) 
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) 
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) 
at java.lang.reflect.Method.invoke(Method.java:597) 
at org.springframework.test.context.junit4.SpringTestMethod.invoke(SpringTestMethod.java:160) 
at org.springframework.test.context.junit4.SpringMethodRoadie.runTestMethod(SpringMethodRoadie.java:233) 
at org.springframework.test.context.junit4.SpringMethodRoadie$RunBeforesThenTestThenAfters.run(SpringMethodRoadie.java:333) 
at org.springframework.test.context.junit4.SpringMethodRoadie.runWithRepetitions(SpringMethodRoadie.java:217) 
at org.springframework.test.context.junit4.SpringMethodRoadie.runTest(SpringMethodRoadie.java:197) 
at org.springframework.test.context.junit4.SpringMethodRoadie.run(SpringMethodRoadie.java:143) 
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.invokeTestMethod(SpringJUnit4ClassRunner.java:160) 
at org.junit.internal.runners.JUnit4ClassRunner.runMethods(JUnit4ClassRunner.java:51) 
at org.junit.internal.runners.JUnit4ClassRunner$1.run(JUnit4ClassRunner.java:44) 
at org.junit.internal.runners.ClassRoadie.runUnprotected(ClassRoadie.java:27) 
at org.junit.internal.runners.ClassRoadie.runProtected(ClassRoadie.java:37) 
at org.junit.internal.runners.JUnit4ClassRunner.run(JUnit4ClassRunner.java:42) 
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:97) 
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:49) 
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38) 
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467) 
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683) 
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390) 
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197) 
Caused by: com.microsoft.sqlserver.jdbc.SQLServerException: Procedure or function 'sp_GetMaybeBGnumberKT' expects parameter '@KT', which was not supplied. 
at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDatabaseError(SQLServerException.java:197) 
at com.microsoft.sqlserver.jdbc.SQLServerStatement.getNextResult(SQLServerStatement.java:1493) 
at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.doExecutePreparedStatement(SQLServerPreparedStatement.java:390) 
at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement$PrepStmtExecCmd.doExecute(SQLServerPreparedStatement.java:340) 
at com.microsoft.sqlserver.jdbc.TDSCommand.execute(IOBuffer.java:4575) 
at com.microsoft.sqlserver.jdbc.SQLServerConnection.executeCommand(SQLServerConnection.java:1400) 
at com.microsoft.sqlserver.jdbc.SQLServerStatement.executeCommand(SQLServerStatement.java:179) 
at com.microsoft.sqlserver.jdbc.SQLServerStatement.executeStatement(SQLServerStatement.java:154) 
at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.execute(SQLServerPreparedStatement.java:322) 
at org.apache.commons.dbcp.DelegatingPreparedStatement.execute(DelegatingPreparedStatement.java:172) 
at org.apache.commons.dbcp.DelegatingPreparedStatement.execute(DelegatingPreparedStatement.java:172) 
at org.springframework.jdbc.core.JdbcTemplate$5.doInCallableStatement(JdbcTemplate.java:987) 
at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:936) 
... 31 more 

Merci

Gunnlaugur

Répondre

0

Vous devez appeler 'declareParameters' pour votre 'SimpleJdbcCall'

+0

J'ai ajouté .declareParameters (new SqlParameter ("@ KT", java.sql.Types.VARCHAR)) mais j'ai la même exception – Gunnlaugur

+0

Une idée de ce qui pourrait causer mon problème? – Gunnlaugur

+1

J'ai résolu le problème en ajoutant l'appel à withoutProcedureColumnMetaDataAccess – Gunnlaugur

0

J'ai eu un message d'erreur semblable, mais le Le vrai problème était que .withSchemaName n'était pas spécifié.

Questions connexes