Spring JDBC Inserting data into Table
$count++; if($count == 1) { #include "../mobilemenu.php"; } if ($count == 2) { include "../sharemediasubfolder.php"; } ?>
We can add data to table using update command of JdbcTemplate.
Update method in JdbcTemplate allows us to add or modify data in tables.
batchUpdate method lets us bulk update data into the tables.
List<CosmicObject> cosmicObjectList
= new ArrayList<CosmicObject>();
// Get sample data ready for CosmicObject
cosmicObjectList.add(new CosmicObject("Earth", "Milky Way",
10000, 1));
cosmicObjectList.add(new CosmicObject("Zanibar", "Andromeda",
4000, 4));
for(CosmicObject cosmicObject: cosmicObjectList)
{
jdbcTemplate.update("INSERT INTO COSMICOBJECT(NAME, GALAXYNAME, WEIGHT, NUMBEROFEARTHYEARS) " +
" VALUES (?, ?, ?, ?)", cosmicObject.getName(), cosmicObject.getGalaxy(),
cosmicObject.getWeight(), cosmicObject.getNumberOfEarthYears());
}
System.out.println("Inserted data into COSMICOBJECT table");
As you can see above, we created a list of CosmicObject records, and then inserted them into COSMICOBJECT table using JdbcTemplate's update method call.