All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.github.matteobertozzi.easerinsights.jdbc.sqlx.SqlDemo Maven / Gradle / Ivy

The newest version!
package io.github.matteobertozzi.easerinsights.jdbc.sqlx;

import io.github.matteobertozzi.easerinsights.jdbc.sqlx.Sql.SqlUpdateDef;
import io.github.matteobertozzi.easerinsights.jdbc.sqlx.SqlDemo.FooTable.FooField;
import io.github.matteobertozzi.easerinsights.jdbc.sqlx.impl.DialectMySql;

public class SqlDemo {
  public static class FooTable {
    public enum FooField { Aaa, Bbb, Ccc }
    public static final String NAME = "foo";
  }

  public static void main(final String[] args) throws Exception {
    final Sql sql = new DialectMySql();
    sql.insertInto(FooTable.NAME, FooField.Aaa, FooField.Bbb);
    final SqlUpdateDef updateDef = sql.update(FooTable.NAME, FooField.Aaa, FooField.Bbb)
      .where()
        .eq(FooField.Aaa).and().eq(FooField.Bbb)
        .and()
        .openExpr().lt(FooField.Ccc).or().gt(FooField.Ccc).closeExpr()
      .bind()
      .build();
    System.out.println(updateDef.sql());

    final SqlExecutor sqlExecutor = new SqlExecutor(null);
    try (SqlExecutor.UpdateQuery query = sqlExecutor.update(updateDef)) {
      query.row().addInt(10).bind();
      query.row().addInt(10).bind();
      query.values(10, 20, "foo");
      query.values(10, 20, "foo");
      query.row().addInt(10).bind();
      query.execute();
    }

    try (SqlExecutor.UpdateQuery query = sqlExecutor.update(updateDef)) {
      query.values(10, 20, "foo");
      query.execute();
    }
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy