473,657 Members | 3,022 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

SQL Server Stored Proc Problem

5 New Member
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 2233
dmjpro
2,476 Top Contributor
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
jynxxxed
5 New Member
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 Top Contributor
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
3633
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 Linux, connecting to MS SQL Server, unless it was already pre-installed by your Linux installation, is to build your own multithreaded TCP socket server on Windows and connect to it through the socket API in PHP on Linux (if you have installed...
13
3035
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 produce a decent version of MS SQL Server, one without a plethora of flaws and limitations? Personally I'd sack the MS SQL Server Chief Architect, start addressing some fundementals and do what MS do best - copy the best functionality of their...
7
6411
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 opened. The reports record source is a query. The query uses the value from the form text box to restrict the query. Table name = EggsTable one of the columns in the table is named: EggColor Form name = EggColorForm Form text box name = ColorTextBox
1
3927
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 rollback if there are errors execution calls to other stored procs. I don't believe my code is accounting for errors occuring in the execution
0
7137
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 TRIGGER statement.) I've also defined a SQL stored proc, and the trigger is set to call this SP. I've posted the simplified source below. I can manually call the stored proc, and the external trigger is created without any errors. However, when I do...
2
4274
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 could think of to resolve the problem but nothing works. The stored proc is running in the DB2 Stored Procedures Address Space and both the client and the proc have DSNELI linked into their load modules. The client and proc are running in TSO via...
4
9163
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 sysobjects Where Type = 'P' and Name =
4
4425
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. >From the debug log it seems that the stored procedure can't be found, although I don't know why. Using the control centre, I can see that the procedure name is defined in the database, however it can not be invoked. Can anyone shed any light on...
0
2048
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 don't know how to return the rows the cursor has opened and I don't know how to handle the return set from the proc in my java code. My main problem with that proc is that whether I can retun the result set from the proc without closing the cursor...
8
2797
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, I have a where clause which states : where PermitID like @WorkType order by WorkStart DESC
0
8302
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8820
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8718
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
7314
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6162
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5630
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4150
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2726
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1601
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.