本文整理汇总了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());
}
示例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;
}
示例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;
}
}
示例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();
}
示例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;}
}
示例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();}
}
示例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);
}
}
示例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();
}
}
示例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);
}
示例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);
}
}
示例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;
}
示例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;
}
}
示例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
}
}
}
示例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();
}
示例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);
}
}
}