2

i am inserting a row in a table with kotlin exposed using a raw sql. Is it possible to return the row id?

val sql: String = 
"""
INSERT INTO customer (name, city) VALUES ('Tom', 'Dublin')
"""
TransactionManager.current().connection.prepareStatement(sql, true).executeUpdate()
nusmanov
  • 451
  • 4
  • 15

1 Answers1

0
conn.prepareStatement(sqlString).use { statement ->
   statement.executeUpdate()
   val insertedId = (statement as ClientPreparedStatement).lastInsertID                       
 }

I use kotlin server only 6 hours, maybe it can't be 100% correct, but I could get the id only with cast object (found out with ide debugger).

Timur Oksak
  • 51
  • 1
  • 2