none
Can't call stored procedure with JDBC RRS feed

Answers

  • Hi! Initially I had "initialCatalog" parameter in JDBC URL but the right parameter name is "databaseName". Calling the proc works now. Thanks for helping!
    • Marked as answer by Haba7 Wednesday, September 7, 2016 5:54 AM
    Tuesday, September 6, 2016 7:58 PM

All replies

  • Hello,

    What exactly do you mean with "can't call"? Do you get an error message and which one exactly? how does your T-SQL statement look like?


    Olaf Helper

    [ Blog] [ Xing] [ MVP]

    Tuesday, September 6, 2016 6:42 PM
  • Can you check the Java source and application output? See the links in a first message.

    Tuesday, September 6, 2016 6:57 PM
  • Connection connection = DriverManager.getConnection( "jdbc:sqlserver://localhost:1433;integratedSecurity=true;", null, null);

    In connection string you don't specify a database (Initial catalog) where you want to connect, so you are connected to the login default database, which is by default the "master" database, where your customer stored procedure dont't existist; that's why your get "jdbc.SQLServerException: Could not find stored procedure 'MyProc'.

    Change it to

    Connection connection = DriverManager.getConnection( "jdbc:sqlserver://localhost:1433;integratedSecurity=true;Initial Catalog=SQLProcTest;", null, null); 
    to connect directly to your user database SQLProcTest; see http://www.connectionstrings.com/sql-server/


    Olaf Helper

    [ Blog] [ Xing] [ MVP]


    Tuesday, September 6, 2016 7:34 PM
  • Hi! Initially I had "initialCatalog" parameter in JDBC URL but the right parameter name is "databaseName". Calling the proc works now. Thanks for helping!
    • Marked as answer by Haba7 Wednesday, September 7, 2016 5:54 AM
    Tuesday, September 6, 2016 7:58 PM
  • Hi Haba7,

    You could use a fully qualified name as well.

    // Call MyProc
    CallableStatement statement = connection.prepareCall("{? = call [SQLProcTest].[dbo].[MyProc]}");

    Sam Zha
    TechNet Community Support

    Wednesday, September 7, 2016 3:26 AM
    Moderator