Solved

running a MS SQL server 2000 stored procedure

Posted on 2004-08-20
3
156 Views
Last Modified: 2010-03-31
Hi,

I have a table called alpha

I have a store procedure on it alphaADD

EXEC alphaADD 'abc123','1','5'


How do I execute this procedure from a java code that takes three values in text boxes and passes them as an argument

0
Comment
Question by:anshuma
  • 2
3 Comments
 
LVL 35

Expert Comment

by:girionis
Comment Utility
Hi anshuma,

you need a CallableStatement to call a stored procedure. Take a look here for sample code and instruction how to do it: http://www.onjava.com/pub/a/onjava/2003/08/13/stored_procedures.html

Regards
0
 
LVL 2

Accepted Solution

by:
beermequik earned 250 total points
Comment Utility
...
...
...
Exception ex = null
Connection dbCon;

try {
    dbCon = // your connection code

    CallableStatement stmt = dbCon.prepareCall("EXEC alphaADD ?, ?, ?");

    int paramIndex = 0;
    stmt.setString(++paramIndex, //textbox1 value);
    stmt.setString(++paramIndex, //textbox2 value);
    stmt.setString(++paramIndex, //textbox3 value);

    stmt.execute();
} catch (SQLException sqlE) {
    ex := sqlE;
} finally {
    // guarantee you close the connection
    dbConn.close();
    if (ex != null) {
        // process exception or rethrow it.
}

0
 
LVL 2

Expert Comment

by:beermequik
Comment Utility
oops...done forget to initialize dbCon to null when its declared.
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

772 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