Solved

Get return value from SQL stored Procedure with Javascript

Posted on 2010-08-25
2
613 Views
Last Modified: 2012-06-22
Hello experts.

We have a stored procedure written in SQL (MS SQL Server 2005 ):

ALTER PROCEDURE [dbo].[test_insert]

@person_nbr varchar(12) output

AS
BEGIN
      -- SET NOCOUNT ON added to prevent extra result sets from
      -- interfering with SELECT statements.
      SET NOCOUNT ON;

      SELECT @person_nbr = max(last_generated) + 1
      from system_counters
      where counter_type = 'person_nbr'

END


// and the javascript that reads in the SP:

var dbConn = DatabaseConnectionFactory.createDatabaseConnection ('com.microsoft.sqlserver.jdbc.SQLServerDriver','jdbc:sqlserver://localhost:1433;databaseName=Test;','un','pw');
var result = 0;
var sql = "exec dbo.test_insert()"
logger.warn("Running query: " + sql); //changeme to info or debug once its all working
result = dbConn.executeUpdate(sql);

globalMap.put('PER_NBR', result)
dbConn.close();

return message;

----------------------

Utlimate goal is to get the value of the person_nbr variable in the SQL Stored Proc to return and store into a javascript variable.  Any thoughts as to where to code goes wrong?    We get an "unknown syntax" error.

Thanks in advance!
0
Comment
Question by:robthomas09
2 Comments
 
LVL 19

Accepted Solution

by:
elimesika earned 500 total points
ID: 33526302
HI

Change
var sql = "exec dbo.test_insert()"
to
var sql = "exec dbo.test_insert"

0
 

Author Closing Comment

by:robthomas09
ID: 33531253
thanks
0

Featured Post

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Why is this different from all of the other step by step guides?  Because I make a living as a DBA and not as a writer and I lived through this experience. Defining the name: When I talk to people they say different names on this subject stuff l…
For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.

910 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now