473,378 Members | 1,395 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

IDENTITY_VAL_LOCAL AND STORED PROCEDURES DB2 ver 7.2



If I try and do a "SELECT IDENTITY_VAL_LOCAL() FROM SYSIBM.SYSDUMMY1"
after I have run a stored procedure in DB2 version 7.2, I get the last
generated Key before the CallableStatement was executed in the
transaction and not the key generated in my stored procedure.
Is there a way to set the IDENTITY_VAL_LOCAL or have the stored
procedure generated key show up in my IDENTITY_VAL_LOCAL value?

Thanks Mike
Java Code:
CallableStatement proc =
((Connection)this.getConnection()).prepareCall("{c all
ADMIN.PROCEDURE4(?,?,?,?,?,?,?)}");

proc.setString(1, new String("TEST"));
proc.setString(2, new String("TEST"));
proc.setString(3, new String("TEST"));
proc.setString(4, new String(""));
proc.setString(5, new String("TEST"));
proc.setInt (6, 1);
proc.setString(7, new String("TEST")); proc.executeUpdate();
System.out.println("last generated ID");
String strSql = "SELECT IDENTITY_VAL_LOCAL() FROM
SYSIBM.SYSDUMMY1" ;

Statement
stmt=((Connection)this.getConnection()).createStat ement();
ResultSet result = stmt.executeQuery(strSql);
while(result.next()) {
String val = result.getString(1);
System.out.println("val = " + val);
}
stmt.close();


SQLJ stored procedure code:
package sqlj_fmb;

import java.sql.*;
import sqlj.runtime.ref.*;

public class PersonNameInsert {
public static void personNameInsert(String iFRST_NM,
String iMDL_NM,
String iLST_NM,
String iSFX_CD,
String iTP,
int iPRSN_LNK,
String iUPDT_USER
)
throws SQLException, Exception {
#sql {
INSERT INTO ADMIN.COPR_PRSN_NM
(
PRSN_NM_LNK,
FRST_NM,
MDL_NM,
LST_NM,
SFX_CD,
TP,
PRSN_LNK,
UPDT_USER,
UPDT_DTTM
)
VALUES
(
DEFAULT,
:iFRST_NM,
:iMDL_NM,
:iLST_NM,
:iSFX_CD,
:iTP,
:iPRSN_LNK,
:iUPDT_USER,
CURRENT TIMESTAMP
)

};

}

}

Nov 12 '05 #1
1 2778
mike wrote:

If I try and do a "SELECT IDENTITY_VAL_LOCAL() FROM SYSIBM.SYSDUMMY1"
after I have run a stored procedure in DB2 version 7.2, I get the last
generated Key before the CallableStatement was executed in the
transaction and not the key generated in my stored procedure.
Is there a way to set the IDENTITY_VAL_LOCAL or have the stored
procedure generated key show up in my IDENTITY_VAL_LOCAL value?

Interesting. That's not how identity_val_local() is meant to work.
Arguably you could open a PMR on it (presuming you have support for V7.2.

Cheers
Serge

PS: identity_val_local() is superceded by SELECT FROM INSERT in V8.1.4.

--
Serge Rielau
DB2 SQL Compiler Development
IBM Toronto Lab
Nov 12 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: jrefactors | last post by:
I want to know the differences between SQL Server 2000 stored procedures and oracle stored procedures? Do they have different syntax? The concept should be the same that the stored procedures...
2
by: scott | last post by:
Hi, Just wondering what sort of problems and advantages people have found using stored procedures. I have an app developed in VB6 & VB.NET and our developers are starting to re-write some of the...
8
by: chunglun | last post by:
Hi, I am using DB2 UDB ESE 8.1.5 on a win2000 server. I tried to use the function IDENTITY_VAL_LOCAL to get the most up-to-date record with following statement: VALUES IDENTITY_VAL_LOCAL()...
2
by: Kent Lewandowski | last post by:
hi all, Recently I wrote some stored procedures using java jdbc code (admittedly my first stab) and then tried to implement the same within java packages (for code reuse). I encountered...
5
by: Tim Marshall | last post by:
I was following the thread "Re: Access Treeview - Is it Safe Yet?" with interest and on reading the post describing Lauren Quantrell's SmartTree, I've run into something I don't understand: Stored...
2
by: Eli | last post by:
Hi all We currently have a strange problem with calling a Stored Procedure (SQL Database) in our C# Project. The only error I get is "System error" which says a lot :) Background: We have...
45
by: John | last post by:
Hi When developing vb.bet winform apps bound to sql server datasource, is it preferable to use SELECTs or stored procedure to read and write data from/to SQL Server? Why? Thanks Regards
28
by: mooreit | last post by:
The purpose for my questions is accessing these technologies from applications. I develop both applications and databases. Working with Microsoft C#.NET and Microsoft SQL Server 2000 Production and...
11
by: peter | last post by:
I am trying to get a SQL stored procedure to use user maintained MQT implicitly which raises questions on when they are used or not used. In theory you would expect the stored procedure to pick up...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.