?
Solved

running a MS SQL server 2000 stored procedure

Posted on 2004-08-20
3
Medium Priority
?
188 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 750 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

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

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

Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
Suggested Courses
Course of the Month12 days, 11 hours left to enroll

777 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