// Collection of code snippets by Arne Vajhøj 
// (from articles on eksperten.dk / vajhoej.dk written sometime between 2004 and now) 
import java.math.BigDecimal;
import java.sql.DriverManager;
import java.sql.Connection;
import java.sql.PreparedStatement;

public class AddJDBC {
    private static void perform(String clznam, String conurl, String usr, String pwd) throws Exception {
        System.out.println(conurl);
        Class.forName(clznam);
        Connection con = DriverManager.getConnection(conurl, usr, pwd);
        PreparedStatement c = con.prepareStatement("INSERT INTO customer VALUES(?,?,?)");
        c.setInt(1, 6);
        c.setString(2, "F company");
        c.setString(3, "6666-6666");
        c.executeUpdate();
        PreparedStatement ca = con.prepareStatement("INSERT INTO customer_actual VALUES(?,?,?,?,?)");
        ca.setInt(1, 6);
        ca.setString(2, "F road 6");
        ca.setString(3, "F town");
        ca.setString(4, "Mr. F");
        ca.setInt(5, 10);
        ca.executeUpdate();
        PreparedStatement o = con.prepareStatement("INSERT INTO order_main VALUES(?,?,?)");
        o.setInt(1, 6);
        o.setInt(2, 6);
        o.setString(3, "In progress");
        o.executeUpdate();
        PreparedStatement ol = con.prepareStatement("INSERT INTO order_line VALUES(?,?,?,?,?)");
        ol.setInt(1, 8);
        ol.setInt(2, 6);
        ol.setString(3, "X stuff");
        ol.setInt(4, 1);
        ol.setBigDecimal(5, new BigDecimal("72.00"));
        ol.executeUpdate();
        con.close();
    }
    public static void main(String[] args) throws Exception {
        if(args.length == 4) {
            perform(args[0], args[1], args[2], args[3]);
        } else if(args.length == 2) {
            perform(args[0], args[1], null, null);
        }
    }
}
