473,385 Members | 1,673 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

SQL Server Stored Proc Problem

I've been reviewing some of the threads here and applying some of the advice and still getting the same error.

Expand|Select|Wrap|Line Numbers
  1. 15:50:26,935 INFO  [STDOUT] java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC][SQLServer]Could not find stored procedure 'getName'.
I'm basically taking a variable coming to my servlet through a JSP page and using it as my search criteria. I know the stored proc will execute through query analyzer, I can execute a regular prepared statement through my servlet, so i know I'm connecting okay, but I'm still baffled. I have included my servlet and SQL Server procedure:

Servlet:


Expand|Select|Wrap|Line Numbers
  1. import java.io.IOException;
  2. import java.sql.CallableStatement;
  3. import java.sql.Connection;
  4. import java.sql.DriverManager;
  5. import java.sql.ResultSet;
  6. import java.sql.SQLException;
  7. import javax.servlet.ServletException;
  8. import javax.servlet.http.HttpServlet;
  9. import javax.servlet.http.HttpServletRequest;
  10. import javax.servlet.http.HttpServletResponse;
  11.  
  12. public class VoidMemberServlet extends HttpServlet {
  13.  
  14.     private static final long serialVersionUID = 1L;
  15.  
  16.     Connection conn = null;
  17.     public VoidMemberServlet() {        
  18.         super();
  19.  
  20.     }
  21.  
  22.     public void destroy() {
  23.         super.destroy();
  24.     }
  25.  
  26.     public void doGet(HttpServletRequest request, HttpServletResponse response)
  27.             throws ServletException, IOException {    
  28.  
  29.         String state = (String)request.getSession().getAttribute("state");
  30.         if(state != "" &&state!=null)
  31.             callProcedure(state);
  32.     }
  33.  
  34.  
  35.     public void doPost(HttpServletRequest request, HttpServletResponse response)
  36.             throws ServletException, IOException {
  37.  
  38.     }
  39.     private void callProcedure(String state)
  40.     {
  41.         try {
  42.             Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance();
  43.             conn = DriverManager.getConnection(
  44.             "jdbc:microsoft:sqlserver://SERVER1:1433;database=test;user=sa;password=password");
  45.  
  46.  
  47.             //PreparedStatement statement = conn.prepareStatement("select * from SERVER1.test.dbo.allUsersinSystem");
  48.             //ResultSet set = statement.executeQuery();
  49.  
  50.             CallableStatement cstmt = conn.prepareCall("{Call getName(?)}");
  51.             cstmt.setString(1,state);
  52.  
  53.             cstmt.execute();
  54.             ResultSet set = cstmt.getResultSet();
  55.  
  56.             cstmt.close();            
  57.             conn.close();
  58.  
  59.             while(set.next())
  60.             {                
  61.                 System.out.println(set.getString("uname"));
  62.             }            
  63.  
  64.         } catch (ClassNotFoundException e) {
  65.  
  66.             e.printStackTrace();
  67.         } catch (SQLException e) {
  68.             // TODO Auto-generated catch block
  69.             e.printStackTrace();
  70.         } catch (InstantiationException e) {
  71.             // TODO Auto-generated catch block
  72.             e.printStackTrace();
  73.         } catch (IllegalAccessException e) {
  74.             // TODO Auto-generated catch block
  75.             e.printStackTrace();
  76.         }
  77.  
  78.     }
  79.  
  80.     public void init() throws ServletException {
  81.  
  82.     }
  83.  
  84. }
There are appropriate execute permissions on all the users and the sproc looks something like:
Expand|Select|Wrap|Line Numbers
  1. CREATE PROCEDURE getName (@State varchar(2))
  2. as
  3. Select uname
  4. FROM allUsersinSystem
  5. WHERE state=@State
  6. GO
I dont know how I can execute a prepared statement on a table in the same database, but I can't execute the sproc.

Any suggestions would be great,

Thanks,

-Dave
Apr 26 '07 #1
3 2222
dmjpro
2,476 2GB
welcome jynxxxed,

actually i m from oracle ... there is a synonym and grand funda.

i m not sure is there any funda in MicroSoft sqlserver.

so u better to forward this post to the database forums.


and i thing i saw in ur code ... that u r accessing the resultset object after closing statement and connection objects.

u must use the resultset object before closing the statement object.

best of luck jynxxxed.
Apr 27 '07 #2
Well,

That's true, I am accessing the result set object after closing the connection and Callable statement, but I thought that since I set the ResultSet while they're still open, I could access it without worrying about the connection.

But I am still unsure why I can't execute the callable statement though, and why I would get the error, "Cannot Find Stored Procedure 'getName' ".. I'm definitely baffled.

Sorry for posting in the wrong section, I will move this thread over to the Database section.

Thanks,

-Dave
Apr 27 '07 #3
dmjpro
2,476 2GB
the resultset object is associated with statement object and the statement object is associated with connection object.
Apr 27 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Google Mike | last post by:
After a lot of thought and research, and playing with FreeTDS and InlineTDS, as well as various ODBC connections, I have determined that the fastest and cheapest way to get up and going with PHP on...
13
by: Jeager | last post by:
Why is it, Microsoft manage to write operating systems and office applications with every bell and whistle facility known to man. Yet, even after years and years of development they still cannot...
7
by: rickcheney | last post by:
I just changed my Access 2002 database to a SQL Server ADP project. I had a form where the user entered a value into a text box and when a command button on the form was clicked a Report was...
1
by: dmalhotr2001 | last post by:
Hi, I have an issue with my query. 1. I have 1 stored proc which have execution calls to multiple stored procs within it. 2. I want to wrap that main stored proc in the transaction and...
0
by: Dave Sisk | last post by:
I've created a system or external trigger on an AS/400 file a.k.a DB2 table. (Note this is an external trigger defined with the ADDPFTRG CL command, not a SQL trigger defined with the CREATE...
2
by: Rhino | last post by:
I am getting an sqlcode of -927 when I execute SQL within a COBOL stored procedure in DB2 OS/390 Version 6 on OS/390. I have looked at the error message for that condition and tried everything I...
4
by: xAvailx | last post by:
Hello: I didn't find any documentation that notes save point names are case sensitive, but I guess they are... Stored Proc to reproduce: /* START CODE SNIPPET */ If Exists (Select * From...
4
by: hicks | last post by:
I'm trying to invoke a DB2 stored procedure. The stored proc is coded in C and compiled to a shared library, which has been placed in the <DB2 dir>/functions directory. The platform is Solaris....
0
by: balaji krishna | last post by:
Hi, I need to handle the return set from COBOL stored procedure from my invoking Java program. I do not know, how many rows the stored proc SQL fetches.I have declared the cursor in that proc, but i...
8
by: rbg | last post by:
I did use query plans to find out more. ( Please see the thread BELOW) I have a question on this, if someone can help me with that it will be great. In my SQL query that selects data from table,...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.