Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5999335
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T00:32:15+00:00 2026-05-23T00:32:15+00:00

I am having difficulty executing a MS SQL Server stored procedure from Java/jsp. I

  • 0

I am having difficulty executing a MS SQL Server stored procedure from Java/jsp. I wish to return a table set of data; the last line of the stored procedure is a regular select statement from a table.

(From this point, executing a stored procedure is a cinch in PHP.)

I took a look at these sites for help:
http://www.2netave.com
http://www.stackoverflow.com

I didn’t realize there’s a function just for stored procedures, as I was using createStatement() instead.

Now, please understand the stored procedure executes perfectly in SQL Server Management Studio and I have had no problems executing ad-hoc queries in jsp/java with createStatement().

I created a simple stored procedure that takes no arguments, just to narrow down the problem:

CREATE PROCEDURE sp_test AS
BEGIN
PRINT 'HELLO WORLD'
END

Here is the code in my jsp page:

Class.forName("net.sourceforge.jtds.jdbc.Driver");
java.sql.Connection conn = java.sql.DriverManager.getConnection("jdbc:jtds:sqlserver://MySQLServer:1433/test", "user", "pass");
java.sql.CallableStatement cs = conn.prepareCall("{call sp_test}"); 
java.sql.ResultSet ResultSet = cs.execute();

The browser is telling me that the page cannot be displayed because an interal server error has occurred. I know this means there is an issue with the code above.

I tried this:

java.sql.ResultSet ResultSet = cs.executeQuery();

And this:

java.sql.CallableStatement cs = conn.prepareCall("{execute sp_test}");

And this:

java.sql.CallableStatement cs = conn.prepareCall("{exec sp_test}");

And nothing worked. Once I can get this working, then I can run an actual stored procedure that returns table data from a select statement. But I can’t even get this dummy stored procedure to work.

What am I doing wrong here?

Thank you.

Update:

Checked the server logs (IIS) and my HTTP proxy, fiddler, and it doesn’t report anything. However, the IIS is using tomcat as the servlet engine for jsp pages. And tomcat log file reported the following:

An error occurred at line: 20 in the jsp file: /test.jsp
Type mismatch: cannot convert from boolean to ResultSet
17: 
18:     java.sql.CallableStatement cs = conn.prepareCall("{call sp_test}");
19:     
20:     java.sql.ResultSet ResultSet = cs.execute();
21: 
22: //  java.sql.ResultSet ResultSet = state.executeQuery(SQL); 
23: 

I tried changing the above to:

cs.execute();

And the log files reported:

- Servlet.service() for servlet jsp threw exception
java.sql.SQLException: The EXECUTE permission was denied on the object 'sp_test', database 'test', schema 'dbo'.

So, I have figured out I have to GRANT EXECUTE to the user. The other issue is returning table data from a stored procedure.

If I have a procedure like this:

CREATE PROCEDURE sp_test2 AS
BEGIN
SELECT * FROM TABLE
END

How do I manipulate the table data in jsp? Would ResultSet work or is that only for ad-hoc queries, as opposed to stored procedures, where one would use createStatement() to execute a query?

Thank you.

Update2:

Solution:

In order to manipulate table data, I had to use this:

java.sql.ResultSet RS = cs.executeQuery();

It failed on execute() and it failed on naming the ResultSet object “ResultSet”. It never complained about this in the past with createStatement(). But for some reason, with stored procedures, it didn’t like this naming convention.

Thank you.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T00:32:16+00:00Added an answer on May 23, 2026 at 12:32 am

    Our server calls stored procs from Java like so – works on both SQL Server 2000 & 2008:

    String SPsql = "EXEC <sp_name> ?,?";   // for stored proc taking 2 parameters
    Connection con = SmartPoolFactory.getConnection();   // java.sql.Connection
    PreparedStatement ps = con.prepareStatement(SPsql);
    ps.setEscapeProcessing(true);
    ps.setQueryTimeout(<timeout value>);
    ps.setString(1, <param1>);
    ps.setString(2, <param2>);
    ResultSet rs = ps.executeQuery();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.