Solved

Get return value from SQL stored Procedure with Javascript

Posted on 2010-08-25
2
606 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
Comment Utility
HI

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

0
 

Author Closing Comment

by:robthomas09
Comment Utility
thanks
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Powershell SMO script not working. 18 99
sql server query? 6 26
addressing a specific html page 9 19
SQL Date Retrival 7 25
This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
Viewers will learn how the fundamental information of how to create a table.

771 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

12 Experts available now in Live!

Get 1:1 Help Now