JDBC Statement – Batch Update

A JDBC Statement example to send a batch of SQL commands (drop,create, insert, update) to the database. BatchUpdate.java package com.mkyong.jdbc.statement; import java.math.BigDecimal; import java.sql.Connection; import java.sql.DriverManager; import java.sql.SQLException; import java.sql.Statement; import java.time.LocalDateTime; import java.util.Arrays; public class BatchUpdate { public static void main(String[] args) { try (Connection conn = DriverManager.getConnection( "jdbc:postgresql://127.0.0.1:5432/test", "postgres", "password"); Statement statement = …

Read more

JDBC PreparedStatement – Batch Update

A JDBC PreparedStatement example to send a batch of SQL commands (create, insert, update) to the database. BatchUpdate.java package com.mkyong.jdbc.preparestatement; import java.math.BigDecimal; import java.sql.*; import java.time.LocalDateTime; import java.util.Arrays; public class BatchUpdate { public static void main(String[] args) { try (Connection conn = DriverManager.getConnection( "jdbc:postgresql://127.0.0.1:5432/test", "postgres", "password"); PreparedStatement psDDL = conn.prepareStatement(SQL_CREATE); PreparedStatement psInsert = conn.prepareStatement(SQL_INSERT); PreparedStatement …

Read more