// Collection of code snippets by Arne Vajhøj 
// (from articles on eksperten.dk / vajhoej.dk written sometime between 2004 and now) 
package demo.sharding;

import java.io.IOException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;

import javax.sql.DataSource;

public class InsertJdbc {
    public static void main(String[] args) throws SQLException, IOException {
        Logger.getLogger("").setLevel(Level.OFF);
        DataSource ds = Config.getDataSource();
        try(Connection con = ds.getConnection()) { 
            try(PreparedStatement ins = con.prepareStatement("INSERT INTO t(id,val) VALUES(?,?)")) {
                int n = 0;
                for(int i = 1; i <= 100; i++) {
                    ins.setInt(1,  i);
                    ins.setString(2, "Item #" + i);
                    n += ins.executeUpdate();
                }
                System.out.printf("%d inserted\n", n);
            }
        }
    }
}
