Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to insert primary key value in database in scala with play framework?
    primarykey
    data
    text
    <p>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</p> <p>what am i doing:</p> <ol> <li>i am taking values from form and then performing some operation on data and then storing values in database .</li> </ol> <p>i went through solutions but the solution they are providing is not working in my application</p> <p>app evolution file:</p> <pre><code># --- !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; </code></pre> <p>and <strong>models/keyword.scala</strong> file</p> <pre><code>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 =&gt; Keyword(id,word,blog,cat,score, summaryId) } } def all(): List[Keyword] = DB.withConnection { implicit c =&gt; SQL("select * from keyword").as(Keyword.keyw *) } def ad(word: String, count: Long, summaryId: String, blog: String, cat: String)={DB.withConnection{implicit c=&gt; val id=SQL("select id from keyword").apply.head SQL("insert into keyword values({id},{word},{blog}, {cat}, {score},{summaryId},{dates})").on('id-&gt;Id(id), 'word-&gt; word,'blog-&gt;blog, 'cat -&gt; cat, 'score-&gt; count, 'summaryId -&gt; summaryId, 'dates-&gt; new DateTime().toDate()).executeUpdate}} </code></pre> <p>contoller file:</p> <p>i am calling ad method to insert into database </p> <pre><code>Keyword.ad(k.word, k.count, link, blog, category) </code></pre> <p>but i am not getting how to insert primary value id into database that is primary key.</p> <p>i set <code>id</code> as a <code>primary key</code> that is <code>auto- increment</code> </p> <p>but when i am calling this method that time how to <strong>give value to id</strong> i am not getting </p> <p>can any one please give me some idea to solve this ?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload