Execute Update and Delete Statements With JdbcTemplate : JdbcTemplate « Spring « Java

Execute Update and Delete Statements With JdbcTemplate

File: context.xml

<?xml version="1.0" encoding="UTF-8"?>

   <bean id="dataSource"

   <property name="driverClassName">

   <property name="url">

   <property name="username">

   <property name="password">


   <bean id="datacon" class="Dataconimpl">
      <property name="dataSource"><ref local="dataSource"/></property>

File: Main.java

import javax.sql.DataSource;

import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.xml.XmlBeanFactory;
import org.springframework.core.io.ClassPathResource;
import org.springframework.jdbc.core.JdbcTemplate;

public class Main {

  public static void main(String[] args) throws Exception {
    BeanFactory factory = new XmlBeanFactory(new ClassPathResource("context.xml"));
    Dataconimpl bean1 = (Dataconimpl) factory.getBean("datacon");
    JdbcTemplate jt = new JdbcTemplate(bean1.dbcon());
    jt.execute("delete from table1  ");
    jt.execute("update table1 set table1.place='' ");


class Dataconimpl implements Datacon {
  private DataSource dataSource;

  public void setDataSource(DataSource ds) {
    dataSource = ds;

  public DataSource dbcon() {
    return dataSource;

interface Datacon {
  public DataSource dbcon();



Spring-UpdateDeleteStatementsWithJdbcTemplate.zip( 2,894 k)

Related examples in the same category

1.Use queryForInt To Execute Aggregate Function
2.Use JdbcTemplate To Execute Delete Statement With Parameter
3.Use JdbcTemplate To Execute Aggregate Function: queryForLong
4.Use JdbcTemplate To Create Table
5.Pass DataSource to se JdbcTemplate
6.Use batchUpdate from JdbcTemplate To Execute Two UpdateStatements
7.UpdateStatement With Two Parameters
8.Query For Rowset
9.Query For Object, Return String
10.Query For Map
11.Query For List, Returns List Of Linked HashMap
12.Query For List
13.Pass Parameter As Object Array
14.Pass Object Array To Query Method In JdbcTemplate
15.Number Of Row Affected
16.Execute Delete Statement
17.Deal With TimeStamp
18.Control Parameter Type In JdbcTemplate.Query