Package com.mysql.management.util

Examples of com.mysql.management.util.QueryUtil


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");
  }
View Full Code Here


      MySQLManager manager = new MySQLManager(mysql);
      conn = manager.getJdbcManager().getConnectionFromPool();

      insertData(conn);

      List<?> l = new QueryUtil(conn).executeQuery("SELECT * FROM test_table LIMIT 10;");
      assertEquals(10, l.size());

    } finally {
      if(conn != null) {
        conn.close();
View Full Code Here

TOP

Related Classes of com.mysql.management.util.QueryUtil

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.