Code Newbie
News     Forums     Search     Members     Sign Up    

My Code Newbie
Username

Password

Articles/Snippets
ASP Classic
ASP.NET
C
C#
C++
HTML / CSS
Java
Javascript
Linux / BSD
Perl
PHP
Python
Ruby
SQL
VB 6
VB.NET

C.N. Friends
  Planet Rome

Link to Us!
Code Newbie
  Code Newbie
    forums

Go Back   Code Forums > Application and Web Development > Java

Reply
 
LinkBack Thread Tools Display Modes
Old 04-15-2005, 10:25 PM   #1 (permalink)
linjylo
Registered User
 
linjylo's Avatar
 
Join Date: Apr 2005
Posts: 3
linjylo is on a distinguished road
how to get inserted OID once insert a record into MySQL

Good day everyone

I need to retrieve inserted OID for record inserted

Code:
public int createRecord(Record record) throws SQLException
{
      String sql="insert into Record(name) values(?)";
      PreparedStatement pstmt = con.prepareStatement(sql,
      ResultSet.TYPE_SCROLL_INSENSITIVE,
      ResultSet.CONCUR_UPDATABLE);

      pstmt.setString(1, record.getName());
      int row=pstmt.executeUpdate();
      pstmt.close();

      int OID=-1;//how to get inserted OID?
      return (OID);
}
anyone who know please advise me, thanks in advance
linjylo is offline   Reply With Quote
Old 04-16-2005, 04:05 AM   #2 (permalink)
Belisarius
Java fanboy
 
Belisarius's Avatar
 
Join Date: Aug 2003
Posts: 1,148
Belisarius is on a distinguished road
pstmt.getGeneratedKeys() might work, I don't know as I haven't used it before.
__________________
GitS
Belisarius is offline   Reply With Quote
Old 05-16-2005, 09:38 AM   #3 (permalink)
Mazzman
Registered User
 
Join Date: Mar 2005
Posts: 7
Mazzman is on a distinguished road
A technique that I usally use is to create and use the DB sequece object of that database.

You select the next sequence value from the DataBase using a SQL select statment like "select sequence_name.NEXTVAL from DUEL", Then use that number when you insert a new row.

Very reliable technique.
Mazzman is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to insert HTML form data into mysql database ? plomon PHP 5 02-06-2005 08:23 AM
Why use explode/implode with MySql insert? Wysocki PHP 6 01-27-2005 05:20 PM
MYSQL - insert jimmyoctane PHP 7 09-15-2003 01:15 PM


All times are GMT -8. The time now is 08:06 PM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.0.0 RC8





Copyright © 2000-2008, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting