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


Java Statement.execute方法代码示例

本文整理汇总了Java中java.sql.Statement.execute方法的典型用法代码示例。如果您正苦于以下问题:Java Statement.execute方法的具体用法?Java Statement.execute怎么用?Java Statement.execute使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.sql.Statement的用法示例。


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

示例1: execute

import java.sql.Statement; //导入方法依赖的package包/类
@Override
public void execute(final String sql) throws DataAccessException {
	if (logger.isDebugEnabled()) {
		logger.debug("Executing SQL statement [" + sql + "]");
	}
	class ExecuteStatementCallback implements StatementCallback<Object>, SqlProvider {
		@Override
		public Object doInStatement(Statement stmt) throws SQLException {
			stmt.execute(sql);
			return null;
		}
		@Override
		public String getSql() {
			return sql;
		}
	}
	execute(new ExecuteStatementCallback());
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:19,代码来源:JdbcTemplate.java

示例2: create

import java.sql.Statement; //导入方法依赖的package包/类
public static Requisicao create(Requisicao requisicao) throws SQLException {
    Statement stm
            = Database.createConnection().
                    createStatement();
    String sql
            = "INSERT INTO requisicoes (`servidor`, `data`, `observacao`) VALUES ('"
            + requisicao.getServidor().getId() + "','"
            + requisicao.getData() + "','"
            + requisicao.getObservacao() + "')";

    stm.execute(sql, Statement.RETURN_GENERATED_KEYS);
    ResultSet rs = stm.getGeneratedKeys();
    rs.next();
    requisicao.setId(rs.getInt(1));
    
    if(requisicao.getItens() != null){
        for (RequisicaoProduto item : requisicao.getItens()) {
            item.setRequisicaoId(requisicao.getId());
            RequisicaoProdutoDAO.create(item);
        }
    }
    
    return requisicao;
}
 
开发者ID:Montanheiro,项目名称:SistemaAlmoxarifado,代码行数:25,代码来源:RequisicaoDAO.java

示例3: updateBorradoUsuarios

import java.sql.Statement; //导入方法依赖的package包/类
public static boolean updateBorradoUsuarios(Usuario fundamentacionObj,
		String usuarioResponsable) {
	Connection conect = ConnectionConfiguration.conectar();

	Statement statement = null;
	fundamentacionObj.changeBorrado();

	String query = "update usuario set borrado='"
			+ fundamentacionObj.isBorrado() + "'";
	query += ", usuario_responsable='" + usuarioResponsable + "'";
	query += " where id =" + fundamentacionObj.getId();
	try {
		statement = conect.createStatement();
		statement.execute(query);
		conect.close();
		return true;
	} catch (SQLException e) {
		e.printStackTrace();
		return false;
	}

}
 
开发者ID:stppy,项目名称:spr,代码行数:23,代码来源:SqlUpdates.java

示例4: updateSetting

import java.sql.Statement; //导入方法依赖的package包/类
public void updateSetting(String key, String value) {
    connect();
    try {
        Statement statement = connection.createStatement();

        String sql = "UPDATE settings SET \n"
                + "value='" + value + "' WHERE parameterName='" + key + "';";

        statement.execute(sql);
    } catch (SQLException ex) {
        System.err.println("Fatal database problem [updateSetting()]: " + ex.getMessage());
        System.exit(1);
    }

    disconnect();
}
 
开发者ID:nick-ivanov,项目名称:icewolf,代码行数:17,代码来源:IWDatabaseHelper.java

示例5: borradoEvidencia

import java.sql.Statement; //导入方法依赖的package包/类
public static boolean borradoEvidencia(Evidencia objeto, String usuarioResponsable){
  	 Connection conect=ConnectionConfiguration.conectar();
  	 Statement statement = null;
  	 objeto.changeBorrado();
  	 
	 String query = "update evidencia set borrado='"+objeto.isBorrado()+"'";
	 		query += ", usuario_responsable='" + usuarioResponsable + "'";
	
		 query+=" where id ="+objeto.getId();
	  	
	 try {
		statement=conect.createStatement();
		statement.execute(query);
	    conect.close();
	    return true;
	 }catch (SQLException e) {e.printStackTrace(); return false;}
}
 
开发者ID:stppy,项目名称:tcp,代码行数:18,代码来源:SqlUpdates.java

示例6: deleteEstrategiaHasObjetivo

import java.sql.Statement; //导入方法依赖的package包/类
public static void deleteEstrategiaHasObjetivo(String id){
 	 Connection conect=ConnectionConfiguration.conectar();
 	 Statement statement = null;
 String 									query = "delete from estrategia_has_objetivo ";
 //if (id!="")								query+= "id=\""+id+"\", ";
 /*if (estrategia_id!="")						query+= "estrategia_id=\""+estrategia_id+"\", ";
 if (estrategia_eje_estrategico_id!="")		query+= "estrategia_eje_estrategico_id=\""+estrategia_eje_estrategico_id+"\", ";
 if (estrategia_linea_transversal_id!="")	query+= "estrategia_linea_transversal_id=\""+estrategia_linea_transversal_id+"\", ";
 if (objetivo_id!="")						query+= "objetivo_id=\""+objetivo_id+"\", ";
 if (objetivo_tipo_objetivo_id!="")			query+= "objetivo_tipo_objetivo_id=\""+objetivo_tipo_objetivo_id+"\", ";
 if (es_principal!="")						query+= "es_principal=\""+es_principal+"\", ";
 query = query.substring(0, query.length()-2);*/
 query+="where id ="+id;
		
try {
	statement=conect.createStatement();
	statement.execute(query);
    conect.close();
} catch (SQLException e) {e.printStackTrace();}
 }
 
开发者ID:stppy,项目名称:spr,代码行数:21,代码来源:SqlDelete.java

示例7: buildDatabase

import java.sql.Statement; //导入方法依赖的package包/类
private void buildDatabase(GeometryImage glayer) {
    try {
        Connection conn = DriverManager.getConnection("jdbc:h2:~/.sumo/VectorData;AUTO_SERVER=TRUE", "sa", "");
        Statement stat = conn.createStatement();
        stat.execute("DROP TABLE \"" + glayer.getName() + "\" IF EXISTS");
        String sql = null;
        File tempfile = File.createTempFile(glayer.getName(), ".csv");
        GenericCSVIO.createSimpleCSV(glayer, tempfile.getAbsolutePath(),false);
        sql = "create table \"" + glayer.getName() + "\" as select * from csvread('" + tempfile.getAbsolutePath() + "')";
        stat.execute(sql);
        stat.close();
        conn.close();
    } catch (Exception ex) {
        logger.error(ex.getMessage(),ex);
    }
}
 
开发者ID:ec-europa,项目名称:sumo,代码行数:17,代码来源:SelectableVectorLayer.java

示例8: updateTipoCatalogoDestinatario

import java.sql.Statement; //导入方法依赖的package包/类
public static void updateTipoCatalogoDestinatario(String id, String nombre,
		String descripcion) {
	Connection conect = ConnectionConfiguration.conectar();
	Statement statement = null;
	String query = "update tipo_catalogo_destinatario set ";
	// if (id!="") query+= "id=\""+id+"\", ";
	if (nombre != "")
		query += "nombre=\"" + nombre + "\", ";
	if (descripcion != "")
		query += "descripcion=\"" + descripcion + "\", ";
	query = query.substring(0, query.length() - 2);
	query += "where id=" + id;

	try {
		statement = conect.createStatement();
		statement.execute(query);
		conect.close();
	} catch (SQLException e) {
		e.printStackTrace();
	}
}
 
开发者ID:stppy,项目名称:spr,代码行数:22,代码来源:SqlUpdates.java

示例9: shouldMeasureStatement

import java.sql.Statement; //导入方法依赖的package包/类
/**
 * Should measure statement.
 *
 * @throws SQLException
 *             the SQL exception
 */
@Test
public void shouldMeasureStatement() throws SQLException {
	Statement statements[] = { dataSource.getConnection().createStatement(),
			dataSource.getConnection().createStatement(1, 1), dataSource.getConnection().createStatement(1, 1, 1) };
	for (Statement statement : statements) {
		statement.execute("select");
		statement.execute("select", 1);
		statement.execute("select", new int[] {});
		statement.execute("select", new String[] {});
		statement.executeQuery("select");
		statement.executeUpdate("select");
		statement.executeUpdate("select", 1);
		statement.executeUpdate("select", new int[] {});
		statement.executeUpdate("select", new String[] {});
		statement.executeLargeUpdate("select");
		statement.executeLargeUpdate("select", 1);
		statement.executeLargeUpdate("select", new int[] {});
		statement.executeLargeUpdate("select", new String[] {});
		statement.addBatch("select");
		statement.executeBatch();
		statement.executeLargeBatch();
	}
	assertThat(registry.get("jdbc.Statement.Invocations", "select")).isEqualTo(1L * 15 * statements.length);
	assertThat(registry.get("jdbc.Statement.Durations", "select")).isEqualTo(123456789L * 15 * statements.length);
}
 
开发者ID:mevdschee,项目名称:tqdev-metrics,代码行数:32,代码来源:InstrumentedDataSourceTest.java

示例10: setVersionInformation

import java.sql.Statement; //导入方法依赖的package包/类
/**
 * Sets the specified version information in the version table in the
 * database.
 * 
 * @param conn
 *            The database connection.
 * @param versionInfoToSet
 *            The version information to be set.
 * @throws SQLException
 */
private void setVersionInformation(Connection conn,
        DatabaseVersionInfo versionInfoToSet, long time)
        throws SQLException {
    Statement stmt = conn.createStatement();
    try {
        stmt.execute("DELETE FROM VERSION");
    } finally {
        closeStatement(stmt);
    }

    PreparedStatement pStmt = conn
            .prepareStatement("INSERT INTO VERSION(productMajorVersion, productMinorVersion, schemaVersion, migrationDate) VALUES(?,?,?,?)");
    try {
        pStmt.setInt(1, versionInfoToSet.getProductMajorVersion());
        pStmt.setInt(2, versionInfoToSet.getProductMinorVersion());
        pStmt.setInt(3, versionInfoToSet.getSchemaVersion());
        pStmt.setTimestamp(4, new Timestamp(time));
        pStmt.execute();
    } finally {
        closeStatement(pStmt);
    }
}
 
开发者ID:servicecatalog,项目名称:oscm,代码行数:33,代码来源:DatabaseUpgradeHandler.java

示例11: create

import java.sql.Statement; //导入方法依赖的package包/类
public static Usuario create(Usuario usuario) throws SQLException {
    Statement stm
            = Database.createConnection().
                    createStatement();
    String sql
            = "INSERT INTO usuarios (`email`, `senha`, `status`, `admin`, `servidor`) VALUES ('"
            + usuario.getEmail() + "','"
            + usuario.getSenha() + "','"
            + usuario.isAtivo() + "','"
            + usuario.isAdmin() + "','"
            + usuario.getServidor().getId() + "')";

    stm.execute(sql, Statement.RETURN_GENERATED_KEYS);
    ResultSet rs = stm.getGeneratedKeys();
    rs.next();
    usuario.setId(rs.getInt(1));
    return usuario;
}
 
开发者ID:Montanheiro,项目名称:SistemaAlmoxarifado,代码行数:19,代码来源:UsuarioDAO.java

示例12: updateBorradoObjetivosSugeridos

import java.sql.Statement; //导入方法依赖的package包/类
public static boolean updateBorradoObjetivosSugeridos(
		ObjetivoSugerido objetivoSugeridoObjeto, String usuarioResponsable)
		throws ParseException {
	Connection conect = ConnectionConfiguration.conectar();
	Statement statement = null;
	objetivoSugeridoObjeto.changeBorrado();

	String query = "update objetivo_sugerido set borrado='"
			+ objetivoSugeridoObjeto.isBorrado() + "', ";
	query += "usuario_responsable='" + usuarioResponsable + "'";

	query += " where objetivo_id ="
			+ objetivoSugeridoObjeto.getObjetivoId()
			+ " and objetivo_tipo_objetivo_id="
			+ objetivoSugeridoObjeto.getTipoObjetivoId()
			+ " and objetivo_anho="
			+ objetivoSugeridoObjeto.getObjetivoAnho()
			+ " and objetivo_version="
			+ objetivoSugeridoObjeto.getObjetivoVersion()
			+ " and objetivo_sugerido_id="
			+ objetivoSugeridoObjeto.getObjetivoSugeridoId()
			+ " and objetivo_sugerido_tipo_id="
			+ objetivoSugeridoObjeto.getObjetivoSugeridoTipoId()
			+ " and objetivo_sugerido_anho="
			+ objetivoSugeridoObjeto.getObjetivoSugeridoAnho()
			+ " and objetivo_sugerido_version="
			+ objetivoSugeridoObjeto.getObjetivoSugeridoVersion();
	try {
		statement = conect.createStatement();
		statement.execute(query);
		conect.close();
		return true;
	} catch (SQLException e) {
		e.printStackTrace();
		return false;
	}
}
 
开发者ID:stppy,项目名称:spr,代码行数:38,代码来源:SqlUpdates.java

示例13: run

import java.sql.Statement; //导入方法依赖的package包/类
public void run(Connection connection, String sql) throws SQLException {
	Statement stmt = connection.createStatement();
	try {
		stmt.execute(sql);
	} finally {
		try {
			stmt.close();
		} catch (SQLException e) {
			// ignore
		}
	}
}
 
开发者ID:xsonorg,项目名称:tangyuan2,代码行数:13,代码来源:SqlActuator.java

示例14: createDatabase

import java.sql.Statement; //导入方法依赖的package包/类
private static void createDatabase() throws SQLException {

        new File("testdb.backup").delete();
        new File("testdb.data").delete();
        new File("testdb.properties").delete();
        new File("testdb.script").delete();

        jdbcDataSource dataSource = new jdbcDataSource();

        dataSource.setDatabase("jdbc:hsqldb:testdb");

        Connection con   = dataSource.getConnection("sa", "");
        String[]   saDDL = {
            "CREATE CACHED TABLE XB (EIACODXA VARCHAR(10) NOT NULL, LSACONXB VARCHAR(18) NOT NULL, ALTLCNXB VARCHAR(2) NOT NULL, LCNTYPXB VARCHAR(1) NOT NULL, LCNINDXB VARCHAR(1), LCNAMEXB VARCHAR(19), UPDT_BY VARCHAR(32), LST_UPDT TIMESTAMP, CONSTRAINT XPKXB PRIMARY KEY (EIACODXA, LSACONXB, ALTLCNXB, LCNTYPXB));",

//            "CREATE INDEX XIF2XB ON XB (EIACODXA);",
            "CREATE CACHED TABLE CA ( EIACODXA VARCHAR(10) NOT NULL, LSACONXB VARCHAR(18) NOT NULL, ALTLCNXB VARCHAR(2) NOT NULL, LCNTYPXB VARCHAR(1) NOT NULL, TASKCDCA VARCHAR(7) NOT NULL, TSKFRQCA NUMERIC(7,4), UPDT_BY VARCHAR(32), LST_UPDT TIMESTAMP, CONSTRAINT XPKCA PRIMARY KEY (EIACODXA, LSACONXB, ALTLCNXB, LCNTYPXB, TASKCDCA),        CONSTRAINT R_XB_CA FOREIGN KEY (EIACODXA, LSACONXB, ALTLCNXB, LCNTYPXB) REFERENCES XB ON DELETE CASCADE);",

//            "CREATE INDEX XIF26CA ON CA ( EIACODXA, LSACONXB, ALTLCNXB, LCNTYPXB);"
        };
        Statement stmt = con.createStatement();

        for (int index = 0; index < saDDL.length; index++) {
            stmt.executeUpdate(saDDL[index]);
        }

        stmt.execute("SHUTDOWN");
        con.close();
    }
 
开发者ID:parabuild-ci,项目名称:parabuild-ci,代码行数:30,代码来源:TestCascade.java

示例15: shutdown

import java.sql.Statement; //导入方法依赖的package包/类
@Override
public void shutdown(DataSource dataSource, String databaseName) {
	try {
		Connection connection = dataSource.getConnection();
		Statement stmt = connection.createStatement();
		stmt.execute("SHUTDOWN");
	}
	catch (SQLException ex) {
		if (logger.isWarnEnabled()) {
			logger.warn("Could not shutdown embedded database", ex);
		}
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:14,代码来源:AbstractEmbeddedDatabaseConfigurer.java


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