Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: update query is firing first then insert query

  1. #1
    Junior Member
    Join Date
    Apr 2011
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default update query is firing first then insert query

    Hi,
    i have a requirement where first i need to insert list of records in to data base then i need to fire an update query to update some column's value of inserted records. but the problem is first it is firing update query and then insert query. how can prevent firing an update query first. for me insert query should be first then update query. please suggest me. following is code snippet.

    method(){
    if(list != null && list.size() > 0){
    for (EntityClass entityClass : list) {
    this.getHibernateTemplate().merge(entityClass);
    }
    }
    if(true){
    methodUpdate(); //this method calls some updating logic. here i used native update sql query.
    }
    }

    Thanks,
    Salmon


  2. #2
    Member
    Join Date
    Nov 2010
    Posts
    35
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: update query is firing first then insert query

    If your using mysql
    -set a primary key in the database
    -using insert......on duplicate key update .....

    see MySQL :: MySQL 5.0 Reference Manual :: 12.2.5.3 INSERT ... ON DUPLICATE KEY UPDATE Syntax for more info
    I had the same problem and now it works fine for me
    Kurt

Similar Threads

  1. Query
    By amol_kale in forum JDBC & Databases
    Replies: 0
    Last Post: February 18th, 2011, 07:04 AM
  2. SQL query not working
    By mjpam in forum What's Wrong With My Code?
    Replies: 11
    Last Post: September 28th, 2010, 05:15 PM
  3. Access database SQL query help
    By mjpam in forum JDBC & Databases
    Replies: 3
    Last Post: September 8th, 2010, 08:48 AM
  4. [SOLVED] Interesing JButton Query
    By ravjot28 in forum AWT / Java Swing
    Replies: 2
    Last Post: January 14th, 2010, 11:19 AM
  5. MSSQL Query Question
    By sravyen in forum JDBC & Databases
    Replies: 1
    Last Post: October 13th, 2009, 02:47 AM