当前位置: 首页>>代码示例>>Java>>正文


Java Sql类代码示例

本文整理汇总了Java中groovy.sql.Sql的典型用法代码示例。如果您正苦于以下问题:Java Sql类的具体用法?Java Sql怎么用?Java Sql使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


Sql类属于groovy.sql包,在下文中一共展示了Sql类的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: connectionFrom

import groovy.sql.Sql; //导入依赖的package包/类
@Override public Connection connectionFrom(Object source) {
  if (DataSource.class.isAssignableFrom(source.getClass())) {
    return DATA_SOURCE_CONNECTOR.connectionFrom(source);
  } else if (Sql.class.isAssignableFrom(source.getClass())) {
    return GROOVY_SQL_CONNECTOR.connectionFrom(source);
  } else if (Connection.class.isAssignableFrom(source.getClass())) {
    return CONNECTION_CONNECTOR.connectionFrom(source);
  }
  throw new IllegalArgumentException(
    format(
      "Unable to obtain a database connection from an instance of %s",
      source.getClass()
    )
  );
}
 
开发者ID:robfletcher,项目名称:spock-jdbc,代码行数:16,代码来源:DefaultConnector.java

示例2: apply

import groovy.sql.Sql; //导入依赖的package包/类
@Override protected Connection apply(Sql source) throws SQLException {
  if (source.getConnection() != null) {
    return CONNECTION_CONNECTOR.connectionFrom(source.getConnection());
  } else {
    return DATA_SOURCE_CONNECTOR.connectionFrom(source.getDataSource());
  }
}
 
开发者ID:robfletcher,项目名称:spock-jdbc,代码行数:8,代码来源:DefaultConnector.java

示例3: ManagedHikariDataSource

import groovy.sql.Sql; //导入依赖的package包/类
/**
 * Creates a new ManagedHikariDataSource
 * @param configuration the data source configuration
 * @param listeners Optional close listeners
 */
public ManagedHikariDataSource(final HikariConfig configuration, final DataSourceListener... listeners) {
	super(configuration);
	poolName = getPoolName();
	groovySql = new Sql(this);
	dsCacheKey = CACHE_DS_PREFIX + poolName;
	groovydsCacheKey = CACHE_GSQL_PREFIX + poolName;
	if(listeners!=null) {
		for(DataSourceListener listener: listeners) {
			if(listener==null) continue;
			this.listeners.add(listener);
		}
	}
}
 
开发者ID:nickman,项目名称:HeliosStreams,代码行数:19,代码来源:ManagedHikariDataSource.java

示例4: executeInsert

import groovy.sql.Sql; //导入依赖的package包/类
public static int executeInsert(Connection conn, String sql) throws SQLException {
    System.out.println(sql);
    Sql client = new Sql(conn);
    Integer result = (Integer) client.executeInsert(sql).get(0).get(0);
    conn.close();
    return result;
}
 
开发者ID:dianping,项目名称:zebra,代码行数:8,代码来源:SqlExecuteHelper.java

示例5: executeUpdate

import groovy.sql.Sql; //导入依赖的package包/类
public static int executeUpdate(Connection conn, String sql) throws SQLException {
    System.out.println(sql);
    Sql client = new Sql(conn);
    int result = client.executeUpdate(sql);
    conn.close();
    return result;
}
 
开发者ID:dianping,项目名称:zebra,代码行数:8,代码来源:SqlExecuteHelper.java

示例6: executeQuery

import groovy.sql.Sql; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public static List<List<Object>> executeQuery(Connection conn, String sql) throws SQLException {
     System.out.println(sql);
     Sql client = new Sql(conn);
     List<GroovyRowResult> rows = client.rows(sql);

     List<List<Object>> result = new ArrayList<List<Object>>();

     for (GroovyRowResult row : rows) {
         result.add(Lists.newArrayList(row.values()));
     }
     conn.close();
     return result;
 }
 
开发者ID:dianping,项目名称:zebra,代码行数:15,代码来源:SqlExecuteHelper.java

示例7: init

import groovy.sql.Sql; //导入依赖的package包/类
@BeforeClass
public static void init() throws SQLException {
	GroupDataSource ds = createDs();

	Sql sql = new Sql(ds.getConnection());
	sql.execute("CREATE TABLE Persons\n" + "(\n" + "Id int,\n" + "LastName varchar(255),\n"
	      + "FirstName varchar(255),\n" + "Address varchar(255),\n" + "City varchar(255)\n" + ")");
	sql.execute("insert into persons (id,lastname,firstname,address,city) values (1,'','','','')");
}
 
开发者ID:dianping,项目名称:zebra,代码行数:10,代码来源:CatFilterTest.java

示例8: test_connect_fail

import groovy.sql.Sql; //导入依赖的package包/类
@Test(expected = ZebraException.class, timeout = 30000)
public void test_connect_fail() throws SQLException {
	GroupDataSource ds = new GroupDataSource();
	ds.setConfigManagerType(Constants.CONFIG_MANAGER_TYPE_LOCAL);
	ds.setJdbcRef("sample.ds.error");
	ds.setFilter("!wall,cat");
	ds.init();
	new Sql(ds.getConnection()).execute("select 1");
}
 
开发者ID:dianping,项目名称:zebra,代码行数:10,代码来源:CatFilterTest.java

示例9: test_sql_success1

import groovy.sql.Sql; //导入依赖的package包/类
@Test
public void test_sql_success1() throws SQLException {
	GroupDataSource ds = createDs();

	DaoContextHolder.setSqlName("testPreparedStatementQuery");

	new Sql(ds.getConnection()).execute(Constants.SQL_FORCE_WRITE_HINT + "select * from Persons");
}
 
开发者ID:dianping,项目名称:zebra,代码行数:9,代码来源:CatFilterTest.java

示例10: test_sql_rejected_by_flow_control

import groovy.sql.Sql; //导入依赖的package包/类
@Test(expected = SQLException.class)
public void test_sql_rejected_by_flow_control() throws SQLException {
	GroupDataSource ds = new GroupDataSource();
	ds.setConfigManagerType(Constants.CONFIG_MANAGER_TYPE_LOCAL);
	ds.setJdbcRef("sample.ds.v2");
	ds.setFilter("wall,cat");
	ds.init();

	DaoContextHolder.setSqlName("test");

	new Sql(ds.getConnection()).execute("select 1", new Object[0]);
}
 
开发者ID:dianping,项目名称:zebra,代码行数:13,代码来源:CatFilterTest.java

示例11: test_sql_success

import groovy.sql.Sql; //导入依赖的package包/类
@Test
public void test_sql_success() throws SQLException {
	GroupDataSource ds = createDs();

	new Sql(ds.getConnection()).execute(Constants.SQL_FORCE_WRITE_HINT + "select * from Persons");
}
 
开发者ID:dianping,项目名称:zebra,代码行数:7,代码来源:CatFilterTest.java

示例12: test_sql_fail_on_slave

import groovy.sql.Sql; //导入依赖的package包/类
@Test(expected = Exception.class)
public void test_sql_fail_on_slave() throws SQLException {
	GroupDataSource ds = createDs();

	new Sql(ds.getConnection()).execute("select * from xxx");
}
 
开发者ID:dianping,项目名称:zebra,代码行数:7,代码来源:CatFilterTest.java

示例13: getSql

import groovy.sql.Sql; //导入依赖的package包/类
/**
 * @return sql - {return content description}
 */
public static Sql getSql() {
	return sql;
}
 
开发者ID:hongliangpan,项目名称:manydesigns.cn,代码行数:7,代码来源:GroovyDbUtils.java


注:本文中的groovy.sql.Sql类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。