You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user-java@ibatis.apache.org by Dwight Galloway <ds...@utah.gov> on 2005/06/14 00:55:18 UTC
Auto-generated keys using Sybase
there are several examples of the Auto-generated key but not for Sybase, like the examples below can you provide one for sybase I have the following.... can anyone please help.....
******************my java ***************************
// Save the Provider that was created
private ProviderBean saveProvider(ProviderBean pb){
SqlMapClient sqlMap = BSSqlMapConfig.getSqlMapInstance();
try {
sqlMap.startTransaction();
System.out.println("we made it here * INSERT *line 159 pb = ");
Integer generatedProviderID = (Integer) sqlMap.insert("insertProvider", pb);
pb.setId(generatedProviderID);
System.out.println("we made it here line 164 " + pb.getId());
sqlMap.commitTransaction();
}
catch (SQLException e){
e.printStackTrace();
}
finally {
try {
sqlMap.endTransaction();
} catch (SQLException e1) {
e1.printStackTrace();
}
}
return null;
}
************************ my XML *********************
<insert id="insertProvider" parameterClass="gov.utah.dhs.dsamh.bs.beans.ProviderBean">
INSERT INTO
tbl_provider (program, short_program, provider_name,
address, address_2, city,
state, zip_code, zip_code_extension,
area_code, phone, phone_extension,
url_address, email, contact_name,
fax_area, fax, system_user_id,
create_date)
values (#program#, #shortProgram#, #providerName#,
#address1#, #address2#, #city#,
#state#, #zipCode#, #zipCodeExtension#,
#areaCode#, #phone#, #phoneExtension#,
#urlAddress#, #email#, #contactName#,
#faxArea#, #fax#, #systemUser#,
#createDate#)
<selectKey resultClass="Integer" keyProperty="id">
SELECT LAST_INSERT_ID() AS id
</selectKey>
</insert>
<!*Oracle SEQUENCE Example -->
<insert id="insertProduct-ORACLE" parameterClass="com.domain.Product">
<selectKey resultClass="int" keyProperty="id" >
SELECT STOCKIDSEQUENCE.NEXTVAL AS ID FROM DUAL
</selectKey>
insert into PRODUCT (PRD_ID,PRD_DESCRIPTION)
values (#id#,#description#)
</insert>
<!* Microsoft SQL Server IDENTITY Column Example -->
<insert id="insertProduct-MS-SQL" parameterClass="com.domain.Product">
insert into PRODUCT (PRD_DESCRIPTION)
values (#description#)
<selectKey resultClass="int" keyProperty="id" >
SELECT @@IDENTITY AS ID
</selectKey>
</insert>
i
Dwight S. Galloway
(801) 538-4234
dsgallow@utah.gov
Office of Technology
Department of Human Services
MAKE IT A GREAT DAY!
Re: Auto-generated keys using Sybase
Posted by Clinton Begin <cl...@gmail.com>.
Is it not the same as MS SQL Server?
Cheers,
Clinton
On 6/13/05, Dwight Galloway <ds...@utah.gov> wrote:
>
> there are several examples of the Auto-generated key but not for Sybase,
> like the examples below can you provide one for sybase I have the
> following.... can anyone please help.....
>
> ******************my java ***************************
> // Save the Provider that was created
> private ProviderBean saveProvider(ProviderBean pb){
> SqlMapClient sqlMap = BSSqlMapConfig.getSqlMapInstance();
> try {
> sqlMap.startTransaction();
> System.out.println("we made it here * INSERT *line 159 pb = ");
> Integer generatedProviderID = (Integer) sqlMap.insert("insertProvider",
> pb);
> pb.setId(generatedProviderID);
> System.out.println("we made it here line 164 " + pb.getId());
> sqlMap.commitTransaction();
> }
> catch (SQLException e){
> e.printStackTrace();
> }
> finally {
> try {
> sqlMap.endTransaction();
> } catch (SQLException e1) {
> e1.printStackTrace();
> }
> }
> return null;
> }
>
> ************************ my XML *********************
>
> <insert id="insertProvider" parameterClass="
> gov.utah.dhs.dsamh.bs.beans.ProviderBean">
> INSERT INTO
> tbl_provider (program, short_program, provider_name,
> address, address_2, city,
> state, zip_code, zip_code_extension,
> area_code, phone, phone_extension,
> url_address, email, contact_name,
> fax_area, fax, system_user_id,
> create_date)
>
> values (#program#, #shortProgram#, #providerName#,
> #address1#, #address2#, #city#,
> #state#, #zipCode#, #zipCodeExtension#,
> #areaCode#, #phone#, #phoneExtension#,
> #urlAddress#, #email#, #contactName#,
> #faxArea#, #fax#, #systemUser#,
> #createDate#)
>
> <selectKey resultClass="Integer" keyProperty="id">
> SELECT LAST_INSERT_ID() AS id
> </selectKey>
> </insert>
>
>
>
>
>
>
>
> <!*Oracle SEQUENCE Example -->
> <insert id="insertProduct-ORACLE" parameterClass="com.domain.Product">
> <selectKey resultClass="int" keyProperty="id" >
> SELECT STOCKIDSEQUENCE.NEXTVAL AS ID FROM DUAL
> </selectKey>
> insert into PRODUCT (PRD_ID,PRD_DESCRIPTION)
> values (#id#,#description#)
> </insert>
> <!* Microsoft SQL Server IDENTITY Column Example -->
> <insert id="insertProduct-MS-SQL" parameterClass="com.domain.Product">
> insert into PRODUCT (PRD_DESCRIPTION)
> values (#description#)
> <selectKey resultClass="int" keyProperty="id" >
> SELECT @@IDENTITY AS ID
> </selectKey>
> </insert>
>
>
> i
>
> Dwight S. Galloway
> (801) 538-4234
> dsgallow@utah.gov
> Office of Technology
> Department of Human Services
> MAKE IT A GREAT DAY!
>
>