I am working with play framework with scala and i am storing values into database but i am getting error how to insert values in database
what am i doing:
- i am taking values from form and then performing some operation on data and then storing values in database .
i went through solutions but the solution they are providing is not working in my application
app evolution file:
# --- !Ups
create table keyword (
id bigint not null AUTO_INCREMENT primary key,
word varchar(255) not null ,
blog varchar(255) not null ,
cat varchar(255) not null ,
score BIGINT not null ,
summaryId varchar(255) not null,
dates datetime
);
# --- !Downs
drop table keyword;
and models/keyword.scala file
case class Keyword(id: Pk[Long] = NotAssigned,word: String,blog: String,cat: String,score: Long, summaryId: String)
object Keyword {
val keyw = {
get[Pk[Long]]("keyword.id") ~
get[String]("keyword.word")~
get[String]("keyword.blog")~
get[String]("keyword.cat")~
get[Long]("keyword.score") ~
get[String]("keyword.summaryId")map {
case id~word~blog~cat~score~summaryId => Keyword(id,word,blog,cat,score, summaryId)
}
}
def all(): List[Keyword] = DB.withConnection { implicit c =>
SQL("select * from keyword").as(Keyword.keyw *)
}
def ad(word: String, count: Long, summaryId: String, blog: String, cat: String)={DB.withConnection{implicit c=>
val id=SQL("select id from keyword").apply.head
SQL("insert into keyword values({id},{word},{blog}, {cat}, {score},{summaryId},{dates})").on('id->Id(id),
'word-> word,'blog->blog,
'cat -> cat,
'score-> count,
'summaryId -> summaryId,
'dates-> new DateTime().toDate()).executeUpdate}}
contoller file:
i am calling ad method to insert into database
Keyword.ad(k.word, k.count, link, blog, category)
but i am not getting how to insert primary value id into database that is primary key.
i set id
as a primary key
that is auto- increment
but when i am calling this method that time how to give value to id i am not getting
can any one please give me some idea to solve this ?