0

It's not working like this? How to add data?

@Override
public void addArticle(Article article) {
    //Add article
    String sql = "INSERT INTO articles (articleId, title, category) values (?, ?, ?)";
    jdbcTemplate.update(sql, article.getArticleId(), article.getTitle(), article.getCategory());

    //Fetch article id
    sql = "SELECT articleId FROM articles WHERE title = ? and category=?";
    int articleId = jdbcTemplate.queryForObject(sql, Integer.class, article.getTitle(), article.getCategory());

    //Set article id 
    article.setArticleId(articleId);
}
barbsan
  • 3,418
  • 11
  • 21
  • 28
mahesh
  • 1

1 Answers1

0

One way to do it is described below:

Create a file data.sql and keep all your queries inside that file for example

INSERT INTO country (name) VALUES ('India');

and put this file on the classpath.

SpringBoot will pick it up and populate the Entries in the DB.