Solved

running a MS SQL server 2000 stored procedure

Posted on 2004-08-20
3
166 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
ID: 11854198
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
ID: 11854411
...
...
...
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
ID: 11854436
oops...done forget to initialize dbCon to null when its declared.
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
splitOdd10 challenge 5 104
Java Timer (static) 9 43
couple of eclipse 5 35
Custom Java Application connects to database: Which one of the 20? 4 27
For customizing the look of your lightweight component and making it look opaque like it was made of plastic.  This tip assumes your component to be of rectangular shape and completely opaque.   (CODE)
INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
The viewer will learn how to implement Singleton Design Pattern in Java.
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

813 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

15 Experts available now in Live!

Get 1:1 Help Now