2015-01-21 54 views
2

我試圖在apple_reportDB插入一些數據參數太多,但我得到的錯誤爲Too many arguments for method in the insert query顯示方法

import scala.slick.driver.MysqlDriver.simple._ 

case class AppleReport(quantity:String,price:String,sale_amount:String) 

//tables 
class Suppliers(tag: Tag) 
    extends Table[AppleReport](tag, "apple_report") { 

def quantity=column[String]("quantity") 
def price=column[String]("price") 
def sale_amount=column[String]("sale_amount") 

def * =(quantity,price,sale_amount) <> (AffiliateReportFields.tupled,AffiliateReportFields.unapply) 
} 

    //declaring interface 
val suppliers: TableQuery[Suppliers] = TableQuery[Suppliers] 

val db=Database.forURL("jdbc:mysql://localhost:3306/apple_reportDB","root","",null, driver="com.mysql.jdbc.Driver") 
    db.withSession { implicit session => 

//create table 
suppliers.ddl.create 
//Insert data 
suppliers += ("apple","cow","cat") 

    } 

回答

4

Suppliers表延伸Table[AppleReport]。因此,您的insert語句需要case類AppleReport的單個對象。

但是,您正在調用3字符串("apple","cow","cat")等錯誤的方法。將其更改爲AppleReport("apple","cow","cat")並且您的代碼將起作用