Search code examples
mysqlscalaplayframeworkanorm

Make sure query is executed or not with Anorm


update query is returning 1 but the insert query is returning None.

def que3(params) {
 DB.withConnection { implicit c =>
    val i=SQL("UPDATE QUERY").executeUpdate
    val j=SQL("INSERT QUERY").executeInsert
    val k=SQL("INSERT QUERY").executeInsert
    println(i)//1
    println(j)//None
    println(k)//None
 }
}

I want to make sure that those query is do their job or not ? how could I get this.

Or should I go for three method with try catch block?

I am using scala 2.10 with play framework 2.2


Solution

  • You can use executeUpdate as executeInsert is the same thing but returns generated id's (auto inc fields etc) if you need them. It's using the same JDBC call for both of them.

    https://github.com/playframework/playframework/blob/863a9bdf78c25e9161043f3c6f8567b9e12fb3bb/framework/src/anorm/src/main/scala/anorm/Anorm.scala#L375