Java DataSource doInsert(DataSource ds, String tableName, int id, String value)

Here you can find the source of doInsert(DataSource ds, String tableName, int id, String value)

Description

do Insert

License

Open Source License

Declaration

public static void doInsert(DataSource ds, String tableName, int id, String value) 

Method Source Code


//package com.java2s;
import javax.sql.DataSource;
import java.sql.Connection;

import java.sql.SQLException;

public class Main {
    public static void doInsert(DataSource ds, String tableName, int id, String value) {
        try (Connection conn = ds.getConnection()) {
            int updated = conn.createStatement()
                    .executeUpdate(String.format("INSERT INTO %s (id, a) VALUES (%s,'%s')", tableName, id, value));
            System.out.println("INSERT to table " + tableName + " outcome: " + updated);
        } catch (SQLException sqle) {
            throw new RuntimeException("insert failed", sqle);
        }//from  w ww  .j  av  a  2s.  co m
    }
}

Related

  1. createTable(DataSource ds, String ddl)
  2. createTable(DataSource ds, String tableName)
  3. createTableRecommendation(DataSource dataSource)
  4. createTables(DataSource ds)
  5. createTables(final DataSource ds)
  6. doSelect(DataSource ds, String tableName, int id)
  7. execute(DataSource ds, String sql, Object... args)
  8. execute(String execute, DataSource datasource)
  9. executeQuery(DataSource dataSource, String... queries)