public class TestEmbeddedMySQL {
public static void insertData(Connection conn) throws IOException {
String query = "CREATE TABLE `test_table` (`idpublisher` int(11) DEFAULT NULL, `idsite` int(11) DEFAULT NULL, `country_iso` varchar(4) DEFAULT NULL, `idzone` int(11) DEFAULT NULL, `hits` int(11) DEFAULT NULL, `cpm_value` double DEFAULT NULL, `ddate` varchar(16) DEFAULT NULL) ENGINE=InnoDB DEFAULT CHARSET=latin1";
QueryUtil util = new QueryUtil(conn);
util.execute(query);
util.execute("BEGIN");
for(String insert : Files.readLines(new File("src/test/resources/test.mysql"),
Charset.defaultCharset())) {
String[] fields = insert.split(",");
String q = "INSERT INTO test_table VALUES (";
for(int i = 0; i < fields.length; i++) {
String val = fields[i];
if(val.length() < 1) {
val = "NULL";
} else {
if(i == 2 || i == 6) {
val = "'" + val + "'";
}
}
q += val;
if(i != fields.length - 1) {
q += ",";
}
}
q += ");";
util.execute(q);
}
util.execute("COMMIT");
}