Question

So I have JPA, Hibernate, and etc set up in my Play! Framework application. The database connects and etc., but I do not get at all how to run a simple query on a controller. Could someone provide me a simple controller class that directly executes a query? (Ex. "create table tablename")

I am looking for a Java example.

Was it helpful?

Solution 2

Take a look into official JPA sample, you'll find there some sample queries (in models)

OTHER TIPS

below code in scala is working in controller, but use model for this

 case class City(city: Int, town: Int)
  def userCities(id: String) = Action{
  var info:List[controllers.MyController.City]=List()
  val data=DB.withConnection {
    implicit Connection =>
       val sql = "SELECT city ,town FROM cities WHERE userId=118376027237390  limit 0,1"
       val res = SQL(sql)
  info = res().map(row => City(row[Int]("city"), row[Int]("town"))).toList
  println(info)
  }
   Ok(write(info))
  }
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top