Well, does anyone know how to get the
Last Insert ID from the INSERT query?
conn.executeUpdate("INSERT...");
? insert ID ?
Last Insert ID from the INSERT query?
conn.executeUpdate("INSERT...");
? insert ID ?
var dbConn = DatabaseConnectionFactory.createDatabaseConnection('com.mysql.jdbc.Driver','jdbc:mysql://somdb.com:3306/testdb','dbuser','dbpassword'); var result = dbConn.executeUpdate("INSERT IGNORE INTO hl7_messages (message) VALUES ('who doesn't like bananas?')", dbConn.RETURN_GENERATED_KEYS); globalMap.put('id_for_test',result); dbConn.close();
Can't find method com.webreach.mirth.server.util.DatabaseConnection.executeUpdate(string,org.mozilla.javascript.Undefined)
var dbConn = DatabaseConnectionFactory.createDatabaseConnection('com.mysql.jdbc.Driver','jdbc:mysql://shportal.com:3306/shportal_prod','bleh','bleh'); var result = dbConn.executeUpdate("INSERT IGNORE INTO registrations (firstname) VALUES ('thundercats')"); var lastid = dbConn.executeCachedQuery('SELECT LAST_INSERT_ID()'); var bleh = "nothing"; while (lastid.next()) { var bleh = lastid.getInt(1); } globalMap.put('last_id', bleh); dbConn.close();
var sql = "INSERT IGNORE INTO <TABLE> SET `<COLUMN1>`='<VALUE1>',`<COLUMN2>`='<VALUE2>', `<COLUMN3>`='<VALUE3>' ON DUPLICATE KEY UPDATE `<ID_COLUMN>`=LAST_INSERT_ID('<ID_COLUMN>')"; // all updates go here (if you want) sql += ",`<COLUMN2>`='<VALUE2>', `<COLUMN3>`='<VALUE3>'"; var result = dbConn.executeUpdate(sql); // done create/update at this point. // to get last inserted/updated id, do this var res = dbConn.executeCachedQuery("SELECT LAST_INSERT_ID() AS id"); var id; if (res.next()) { id = id_res.getString('id'); } // id is your last_insert_id
We process personal data about users of our site, through the use of cookies and other technologies, to deliver our services, personalize advertising, and to analyze site activity. We may share certain information about our users with our advertising and analytics partners. For additional details, refer to our Privacy Policy.
By clicking "I AGREE" below, you agree to our Privacy Policy and our personal data processing and cookie practices as described therein. You also acknowledge that this forum may be hosted outside your country and you consent to the collection, storage, and processing of your data in the country where this forum is hosted.
Comment