Example usage for java.sql PreparedStatement execute

List of usage examples for java.sql PreparedStatement execute

Introduction

In this page you can find the example usage for java.sql PreparedStatement execute.

Prototype

boolean execute() throws SQLException;

Source Link

Document

Executes the SQL statement in this PreparedStatement object, which may be any kind of SQL statement.

Usage

From source file:io.apiman.gateway.test.junit.servlet.ServletGatewayTestServer.java

/**
 * Initialize the DB with the apiman gateway DDL.
 * @param connection//from   w  ww.j  av  a  2 s.  c om
 */
private static void initDB(Connection connection) throws Exception {
    ClassLoader cl = ServletGatewayTestServer.class.getClassLoader();
    URL resource = cl.getResource("ddls/apiman-gateway_h2.ddl");
    try (InputStream is = resource.openStream()) {
        DdlParser ddlParser = new DdlParser();
        List<String> statements = ddlParser.parse(is);
        for (String sql : statements) {
            PreparedStatement statement = connection.prepareStatement(sql);
            statement.execute();
        }
    }
}

From source file:com.concursive.connect.web.modules.upgrade.utils.UpgradeUtils.java

/**
 * Records a database version as being executed
 *
 * @param db      The feature to be added to the Version attribute
 * @param version The feature to be added to the Version attribute
 * @throws SQLException Description of the Exception
 *///from   w  ww . j av  a  2s .com
public static void addVersion(Connection db, String version) throws SQLException {
    // Add the specified version
    PreparedStatement pst = db.prepareStatement(
            "INSERT INTO database_version " + "(script_filename, script_version) VALUES (?, ?) ");
    pst.setString(1, DatabaseUtils.getTypeName(db) + "_" + version);
    pst.setString(2, version);
    pst.execute();
    pst.close();
}

From source file:com.keybox.manage.db.ProfileSystemsDB.java

/**
 * deletes all systems for a given profile
 *
 * @param profileId profile id/*  w  ww  .j  av a 2  s .com*/
 */
public static void deleteAllSystemsFromProfile(Long profileId) {

    Connection con = null;
    try {
        con = DBUtils.getConn();
        PreparedStatement stmt = con.prepareStatement("delete from system_map where profile_id=?");
        stmt.setLong(1, profileId);
        stmt.execute();
        DBUtils.closeStmt(stmt);
    } catch (Exception e) {
        e.printStackTrace();
    }
    DBUtils.closeConn(con);
}

From source file:com.keybox.manage.db.ProfileDB.java

/**
 * updates profile//from w w w.j a v  a 2 s.com
 *
 * @param profile profile object
 */
public static void updateProfile(Profile profile) {

    Connection con = null;
    try {
        con = DBUtils.getConn();
        PreparedStatement stmt = con.prepareStatement("update profiles set nm=?, desc=? where id=?");
        stmt.setString(1, profile.getNm());
        stmt.setString(2, profile.getDesc());
        stmt.setLong(3, profile.getId());
        stmt.execute();
        DBUtils.closeStmt(stmt);

    } catch (Exception e) {
        log.error(e.toString(), e);
    } finally {
        DBUtils.closeConn(con);
    }
}

From source file:com.wso2telco.util.DbUtil.java

public static void incrementSuccessPinAttempts(String sessionId) throws SQLException, AuthenticatorException {

    Connection connection = null;
    PreparedStatement ps = null;

    String sql = "update multiplepasswords set attempts=attempts +1 where ussdsessionid = ?;";

    connection = getConnectDBConnection();

    ps = connection.prepareStatement(sql);

    ps.setString(1, sessionId);/*from  w ww  .  j a  va 2s  .c  o  m*/
    ps.execute();

    if (connection != null) {
        connection.close();
    }
}

From source file:gov.nih.nci.ncicb.tcga.dcc.dam.util.TempClinicalDataLoader.java

private static void setForeignKeys() throws SQLException {
    String updateSql = "UPDATE l4_patient l SET l.clinical_patient_id = (SELECT p.patient_id FROM patient p WHERE p.bcrpatientbarcode = l.patient)";
    PreparedStatement stmt = dbConnection.prepareStatement(updateSql);
    stmt.execute();
    updateSql = "update hybridization_ref hr set hr.aliquot_id=(select a.aliquot_id from aliquot a where a.bcraliquotbarcode=hr.bestBarcode)";
    stmt = dbConnection.prepareStatement(updateSql);
    stmt.execute();/*from w  w  w.jav a  2 s  .com*/
}

From source file:com.wso2telco.util.DbUtil.java

public static void updatePin(int pin, String sessionId) throws SQLException, AuthenticatorException {

    Connection connection = null;
    PreparedStatement ps = null;

    String sql = "update multiplepasswords set pin=? where ussdsessionid = ?;";

    connection = getConnectDBConnection();

    ps = connection.prepareStatement(sql);

    ps.setInt(1, pin);//from   ww  w.  ja  va2  s. c o m
    ps.setString(2, sessionId);
    ps.execute();

    if (connection != null) {
        connection.close();
    }
}

From source file:com.example.querybuilder.server.Jdbc.java

public static boolean execute(PreparedStatement preparedStatement, Object... parameters) {
    try {/*from w ww  .j  av a2 s  .  c o  m*/
        initializeParameters(preparedStatement, parameters);
        return preparedStatement.execute();
    } catch (SQLException e) {
        throw new SqlRuntimeException(e);
    }
}

From source file:com.splicemachine.tutorials.model.RULPredictiveModel.java

/**
 * Stored Procedure for Predictions//from   ww  w.  ja v a2s.com
 */
public static void predictRUL(String sensorTableName, String resultsTableName, String savedModelPath,
        int loopinterval) {

    try {

        //Initialize variables
        if (sensorTableName == null || sensorTableName.length() == 0)
            sensorTableName = "IOT.SENSOR_AGG_1_VIEW";
        if (resultsTableName == null || resultsTableName.length() == 0)
            resultsTableName = "IOT.PREDICTION_EXT";
        if (savedModelPath == null || savedModelPath.length() == 0)
            savedModelPath = "/tmp";
        if (!savedModelPath.endsWith("/"))
            savedModelPath = savedModelPath + "/";
        savedModelPath += "model/";

        String jdbcUrl = "jdbc:splice://localhost:1527/splicedb;user=splice;password=admin;useSpark=true";
        Connection conn = DriverManager.getConnection(jdbcUrl);

        SparkSession sparkSession = SpliceSpark.getSession();

        //Specify the data for predictions
        Map<String, String> options = new HashMap<String, String>();
        options.put("driver", "com.splicemachine.db.jdbc.ClientDriver");
        options.put("url", jdbcUrl);
        options.put("dbtable", sensorTableName);

        //Load Model to use for predictins
        CrossValidatorModel cvModel = CrossValidatorModel.load(savedModelPath);

        //Keep checking for new data and make predictions
        while (loopinterval > 0) {
            //Sensor data requiring predictions
            Dataset<Row> sensords = sparkSession.read().format("jdbc").options(options).load();

            //prepare data
            sensords = sensords.na().fill(0);

            //make predictions
            Dataset<Row> predictions = cvModel.transform(sensords)
                    .select("ENGINE_TYPE", "UNIT", "TIME", "prediction")
                    .withColumnRenamed("prediction", "PREDICTION");

            //Save predictions
            String fileName = "temp_pred_" + RandomStringUtils.randomAlphabetic(6).toLowerCase();

            predictions.write().mode(SaveMode.Append).csv("/tmp/data_pred/predictions");

            //Mark records for which predictions are made
            PreparedStatement pStmtDel = conn.prepareStatement(
                    "delete  from IOT.TO_PROCESS_SENSOR s where exists (select 1 from IOT.PREDICTIONS_EXT p where p.engine_type = s.engine_type and p.unit= s.unit and p.time=s.time )");
            pStmtDel.execute();
            pStmtDel.close();
        }

    } catch (SQLException sqle) {
        System.out.println("Error  :::::" + sqle.toString());
        LOG.error("Exception in getColumnStatistics", sqle);
        sqle.printStackTrace();
    }

}

From source file:com.wso2telco.util.DbUtil.java

public static void updateMultiplePasswordNoOfAttempts(String username, int attempts)
        throws SQLException, AuthenticatorException {

    Connection connection = null;
    PreparedStatement ps = null;

    String sql = "update `multiplepasswords` set  attempts=? where  username=?;";

    connection = getConnectDBConnection();

    ps = connection.prepareStatement(sql);

    ps.setInt(1, attempts);/*w  w  w.  ja  v  a2 s  .  c  o  m*/
    ps.setString(2, username);
    ps.execute();

    if (connection != null) {
        connection.close();
    }
}