コード例 #1
0
ファイル: UserServiceImpl.java プロジェクト: jrchens/simple
 @Autowired
 public void setDataSource(DataSource dataSource) {
   jdbcInsert = new SimpleJdbcInsert(dataSource);
   jdbcInsert.setTableName("tb_user");
   jdbcInsert.setGeneratedKeyName("user_id");
   jdbcTemplate = new JdbcTemplate(dataSource);
 }
コード例 #2
0
 @Override
 public void insert(Transaction transaction) throws SQLException {
   logger.debug("Inserting transaction with type [{}]", transaction.getFlockId());
   Map<String, Object> valuesToInsert = new HashMap<String, Object>();
   valuesToInsert.put("FlockID", transaction.getFlockId());
   valuesToInsert.put("Name", transaction.getName());
   valuesToInsert.put("Expenses", transaction.getExpenses());
   valuesToInsert.put("Revenues", transaction.getRevenues());
   jdbcInsert.setGeneratedKeyName("ID");
   jdbcInsert.execute(valuesToInsert);
 }
コード例 #3
0
ファイル: Database.java プロジェクト: janmurin/KoprVelkyHlad
  public synchronized CookingRecipe insertCookingRecipe(CookingRecipe recipe) throws Exception {
    System.out.println("Database: insertCookingRecipe(" + recipe + ")");
    SimpleJdbcInsert insert = new SimpleJdbcInsert(jdbcTemplate);
    insert.withTableName("recipes");
    insert.setGeneratedKeyName("id");
    Map<String, Object> mapa = new HashMap<String, Object>();
    mapa.put("recipe_name", recipe.getName());
    mapa.put("author", recipe.getAuthor());
    mapa.put("guide", recipe.getGuide());
    // mapa.put("incident_ID", incidentID);
    Number insertedRecipeId = insert.executeAndReturnKey(mapa);
    recipe.setId(insertedRecipeId.longValue());

    insertIngredients(recipe.getIngredients(), insertedRecipeId.longValue());
    for (CookingIngredient ci : recipe.getIngredients()) {
      ci.setRecipe_id(insertedRecipeId.longValue());
    }
    return recipe;
  }