Re: @@IDENTITY correct syntax?
From: Mike (mikekelly100_at_hotmail.com)
Date: 12/15/03
- Previous message: Ray Williams: "Using JDOM to Parse XML and Insert into DB with JDBC"
- In reply to: gnazio: "Re: @@IDENTITY correct syntax?"
- Next in thread: Leo Gaggl: "Re: @@IDENTITY correct syntax?"
- Reply: Leo Gaggl: "Re: @@IDENTITY correct syntax?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 15 Dec 2003 13:59:28 -0800
> Try this and let me know...
> ...
> // insert new thread
> String threadQuery = "insert into threads (forumID, threadTitle,views)
> values ('"+forumID+"','"+threadTitle+"','"+views+"')";
> myStatement.executeUpdate(threadQuery);
>
> ResultSet rs = myStatement.executeQuery("select @@IDENTITY");
> rs.next();
> int threadID = rs.getInt(1);
> rs.close();
>
> // insert new post
> String postsQuery = "insert into posts (threadID, forumID, userName,
> comments, submitDate, picURL, picCaption)
> values('"+threadID+"','"+forumID+"','"+userName+"','"+comments+"','"+submitDate+"','"+imageURL+"','"+imageCaption+"')";
> myStatement.executeUpdate(postsQuery);
> ...
Hi,
That seems to work well. However, is it possible that another user
could make an insert just after this one, so that the @@IDENTITY value
returned is that created by the second, wrong insert? Or will this
example only return the identity value created by myStatement's
executeUpdate?
Thanks,
Mike
- Previous message: Ray Williams: "Using JDOM to Parse XML and Insert into DB with JDBC"
- In reply to: gnazio: "Re: @@IDENTITY correct syntax?"
- Next in thread: Leo Gaggl: "Re: @@IDENTITY correct syntax?"
- Reply: Leo Gaggl: "Re: @@IDENTITY correct syntax?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]