Home > Ask the AS/400 Experts > iSeries Web Development Questions & Answers > Calling a SQL stored procedure
Ask The iSeries 400 Expert: Questions & Answers
EMAIL THIS

Calling a SQL stored procedure

Jim Mason EXPERT RESPONSE FROM: Jim Mason

Pose a Question
Other iSeries 400 Categories
Meet all iSeries 400 Experts
Become an Expert for this site


Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   


>
QUESTION POSED ON: 01 November 2002
I need to call an SQL stored procedure written for a MS NT server to update a server table. My Java program will be running from an iSeries, connecting to the NT server and calling the SQL stored procedure stored in the server to update the table. I have no idea what the syntax is or how to do it. Do you know of any articles on this subject?

>

The exact format of a stored procedure call is dependent on the specific database manager you are using. You didn't mention that. Most database systems support the SQL CallableStatement protocol. I have some simple examples calling a stored procedure in DB2 on NT. IF you have a choice, DB2 offers more options and is easier to create stored procedures than SQL Server.

1) A Java stored procedure

// this is a segment from a method in the Java class

     Connection con =   
DriverManager.getConnection("jdbc:default:connection");
        PreparedStatement stmt = null;
        ResultSet rs = null;
        String sql =  "SELECT"
            + "    CHAR('JMASON3'),"
            + "    EMPLOYEE.EMPNO AS EMPNO,"
            + "    EMPLOYEE.SALARY +  EMPLOYEE.BONUS +
EMPLOYEE.COMM,"
            + "    CHAR('RAN')"  FROM   EMPLOYEE"
            + " WHERE     (    ( EMPLOYEE.EMPNO =  ? 
)  )";
        stmt = con.prepareStatement( sql );
        stmt.setString( 1, emnpno );
        rs = stmt.executeQuery();
        rs.next();
        total_pay[0] = rs.getBigDecimal(3, 2); 

2) A Java client calling the stored procedure

 
// this is a segment in the client class calling 
// the procedure


			dbConn = ( Connection)
java.sql.DriverManager.getConnection(aUrl, "jem",
"jem");
			aCallStmt = (CallableStatement)
dbConn.prepareCall(stmt);
aCallStmt.setString(1, libName);
aCallStmt.setString(2, empno);
aCallStmt.registerOutParameter(3,
java.sql.Types.DECIMAL, 2);
aCallStmt.registerOutParameter(4,
java.sql.Types.CHAR);
aCallStmt.execute();
_total_pay = aCallStmt.getBigDecimal(3, 2);
setRunStatus("done");
result = _total_pay.toString();

//	next close statement, connection if needed 

==================================
MORE INFORMATION ON THIS TOPIC
==================================

Ask your Web development questions--or help out your peers by answering them--in our live discussion forums.

The Best Web Links: tips, tutorials and more.

Check out this live Q&A with Dave Slater and Jim Mason, How to best get started with WebSphere Development Tools.


Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   



RELATED CONTENT
iSeries Web Development
JDBCODBC functionality -- Java to Excel for complex workbooks
Accessing AS/400 data using Excel ODBC drivers
IBM WebSphere Studio Application Developer error
Database pooling on iSeries
Connecting WebSphere to AS/400 for image retrieval
Retrieving the value selected by a user
Condense ILE service program procedures
WebSphere error during login process
Connecting WebSphere to a DB2 database
WebFacing error: User ID or password invalid

Web Development
Implementing a browser interface in COBOL: Creating your graphic Web page
Implementing a browser interface in COBOL: Getting started
IBM i shop boosts online sales with RPG-based Web platform
Migrating from RPG to EGL on IBM i
Groovy programming on IBM i
Running PHP open source applications: NOBODY needs authority
Zend Web software teams up with IBM System i
The best technologies and tools for System i programmers in 2009
Seven IBM i project lessons learned in 2008
AS/400 lessons from the past, present, and future: A holiday tale

iSeries Java programming
Groovy programming on IBM i
EGL Rich UI on IBM i: Do you Dojo?
Programming for the Web on the IBM i, what is possible
Database performance comparisons on IBM i
Database drivers on the i: MySQL vs. IBM Toolbox
How to: Output SQL script to a text file from an AS/400
Application modernization for the iSeries: Why bother?
JDBCODBC functionality -- Java to Excel for complex workbooks
Necessity leads to iSeries Watchdog development
Accessing AS/400 data using Excel ODBC drivers
iSeries Java programming Research

RELATED GLOSSARY TERMS
Terms from Whatis.com − the technology online dictionary
WebSphere Development Studio Client (WDSC)  (Search400.com)

RELATED RESOURCES
2020software.com, trial software downloads for accounting software, ERP software, CRM software and business software systems
Search Bitpipe.com for the latest white papers and business webcasts
Whatis.com, the online computer dictionary



Search and Browse the Expert Answer Center
Search and browse more than 25,000 question and answer pairs from more than 250 TechTarget industry experts.
Browse our Expert Advice



iSeries Networking - Printing, Remote Access, TCP/IP
HomeNewsTopicsITKnowledge ExchangeTipsBlogsAsk the ExpertsMultimediaWhite PapersProducts
About Us  |  Contact Us  |  For Advertisers  |  For Business Partners  |  Site Index  |  RSS
SEARCH 
TechTarget provides technology professionals with the information they need to perform their jobs - from developing strategy, to making cost-effective purchase decisions and managing their organizations' technology projects - with its network of technology-specific websites, events and online magazines.

TechTarget Corporate Web Site  |  Media Kits  |  Site Map




All Rights Reserved, Copyright 1999 - 2009, TechTarget | Read our Privacy Policy
  TechTarget - The IT Media ROI Experts