mysqlscalaplay2-mini

can't resolve symbol scala play2 with mysql result


Guys I am trying to get some results from mysql database and I am having error with fetching it onto scala.html file. Here are my codes:

/*Customers.scala. Its controller*/
package controllers

import play.api._
import play.api.mvc._
import models.Customers

object Customers extends Controller{

    def customer = Action{

        val nb_customers = Customers.allCustomers

        Ok(views.html.customer(nb_customers)) //I am having error here.

    }
    // End of customer Action.

}
// End of Customer controller.



/*Now Customers.scala model*/

package models
import anorm._
import play.api.db._
import play.api.Play.current

case class Customers(CustomersID: Int, Name: String)

object Customers {

    def allCustomers = {

        DB.withConnection {implicit connection =>

            SQL("Select * from Customers")().map{row =>

                Customers(

                    CustomersID = row[Int]("CustomersID"),
                    Name = row[String]("Name")

                )
                // End of Customers object.
            }.toList
            // SQL ends.

        }
        // With connection.

    }
    // End of allCustomers.

}
// End of of Customers.

Please note, I am using JDBC driver for mysql connection in conf/application.conf file

Please help me out here. Thanks a lot.


Solution

  • There is a namespace conflict between your Customers controller and model, as both are in the scope. There are two things you can do to fix this.

    1. Rename your model to something different, like Customer.

    2. Change Customers.allCustomers to models.Customers.allCustomers to differentiate from controllers.Customers.