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:fr.gael.dhus.server.http.webapp.symmetricDS.SymmetricDSWebapp.java

@Override
public void afterPropertiesSet() throws Exception {
    if (!scalabilityManager.getClearDB()) {
        return;/*from  w ww . j  a  v a  2 s  .  c  om*/
    }
    PreparedStatement ps = datasource.getConnection().prepareStatement(
            "SELECT TRIGGER_NAME FROM INFORMATION_SCHEMA.TRIGGERS WHERE TRIGGER_NAME LIKE 'SYM_%';",
            ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);

    ResultSet rs = ps.executeQuery();
    while (rs.next()) {
        PreparedStatement ps2 = datasource.getConnection()
                .prepareStatement("DROP TRIGGER " + rs.getString("TRIGGER_NAME"));
        ps2.execute();
        ps2.close();
    }
    ps.close();

    ps = datasource.getConnection().prepareStatement(
            "SELECT CONSTRAINT_NAME, TABLE_NAME FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS WHERE CONSTRAINT_NAME LIKE 'SYM_%';",
            ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
    rs = ps.executeQuery();
    while (rs.next()) {
        PreparedStatement ps2 = datasource.getConnection().prepareStatement("ALTER TABLE "
                + rs.getString("TABLE_NAME") + " DROP CONSTRAINT " + rs.getString("CONSTRAINT_NAME"));
        ps2.execute();
        ps2.close();
    }
    ps.close();

    ps = datasource.getConnection().prepareStatement(
            "SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME LIKE 'SYM_%';",
            ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);

    rs = ps.executeQuery();
    while (rs.next()) {
        PreparedStatement ps2 = datasource.getConnection()
                .prepareStatement("DROP TABLE " + rs.getString("TABLE_NAME"));
        ps2.execute();
        ps2.close();
    }
    ps.close();
}

From source file:guru.bubl.module.neo4j_graph_manipulator.graph.FriendlyResourceNeo4j.java

@Override
public void createUsingInitialValues(Map<String, Object> values) {
    Map<String, Object> creationProps = addCreationProperties(values);
    String query = String.format("create (n:%s {1})", GraphElementType.resource);
    NoEx.wrap(() -> {/*  w  w w  .j a v  a2  s .  c  om*/
        PreparedStatement statement = connection.prepareStatement(query);
        statement.setObject(1, creationProps);
        return statement.execute();
    }).get();
}

From source file:ca.phon.ipadictionary.impl.DatabaseDictionary.java

@Override
public void addEntry(String ortho, String ipa) throws IPADictionaryExecption {
    Connection conn = IPADatabaseManager.getInstance().getConnection();
    if (conn != null) {
        String qSt = "INSERT INTO transcript (langId, orthography, ipa) VALUES( ?, ?, ? )";

        try {//w w w  .  jav a  2 s . c om
            checkLangId(conn);
            PreparedStatement pSt = conn.prepareStatement(qSt);
            pSt.setString(1, getLanguage().toString());
            pSt.setString(2, ortho.toLowerCase());
            pSt.setString(3, ipa);

            pSt.execute();
            pSt.close();
        } catch (SQLException e) {
            LOGGER.log(Level.SEVERE, e.getLocalizedMessage(), e);
        }
    }
}

From source file:de.klemp.middleware.controller.Controller.java

@GET
@Path("/start")
public static synchronized String start() {
    PropertyConfigurator.configure("log4j.properties");
    String ok = "ok";
    isBrokerStarted();/*from  w ww  .  j  a v  a  2  s .co  m*/
    controllerToList();
    ActiveDevicesToList();
    deviceActive.put("VLCPlayerIntern,----------------", true);
    createDBConnection();
    try {
        PreparedStatement st = conn.prepareStatement(
                "insert into \"OutputDevices\"(class,topic,enabled) values ('VLCPlayer','----------------','t');");
        st.execute();

    } catch (SQLException e) {
        String message = e.getMessage();
        if (!message.contains("doppelter Schlsselwert")) {
            logger.error("SQL Exception", e);
        }
    }
    closeDBConnection();
    return ok;
}

From source file:lineage2.gameserver.model.entity.Hero.java

/**
 * Method deleteHero.//from w  w w  .j ava 2 s.  co  m
 * @param player Player
 */
public static void deleteHero(Player player) {
    Connection con = null;
    PreparedStatement statement = null;
    try {
        con = DatabaseFactory.getInstance().getConnection();
        statement = con
                .prepareStatement("REPLACE INTO heroes (char_id, count, played, active) VALUES (?,?,?,?)");
        for (Integer heroId : _heroes.keySet()) {
            int id = player.getObjectId();
            if ((id > 0) && (heroId != id)) {
                continue;
            }
            StatsSet hero = _heroes.get(heroId);
            statement.setInt(1, heroId);
            statement.setInt(2, hero.getInteger(COUNT));
            statement.setInt(3, hero.getInteger(PLAYED));
            statement.setInt(4, 0);
            statement.execute();
            if ((_completeHeroes != null) && !_completeHeroes.containsKey(heroId)) {
                _completeHeroes.remove(heroId);
            }
        }
    } catch (SQLException e) {
        _log.warn("Hero System: Couldnt update Heroes");
        _log.error("", e);
    } finally {
        DbUtils.closeQuietly(con, statement);
    }
}

From source file:guru.bubl.module.neo4j_graph_manipulator.graph.Neo4jFriendlyResource.java

@Override
public void createUsingInitialValues(Map<String, Object> values) {
    Map<String, Object> creationProps = addCreationProperties(values);
    String query = String.format("create (n:%s {1})", GraphElementType.resource);
    NoExRun.wrap(() -> {/*from w w w . j  a va 2  s  .  c om*/
        PreparedStatement statement = connection.prepareStatement(query);
        statement.setObject(1, creationProps);
        return statement.execute();
    }).get();
}

From source file:at.becast.youploader.database.SQLite.java

public static int addUpload(File file, Video data, VideoMetadata metadata, Date startAt)
        throws SQLException, IOException {
    PreparedStatement prest = null;
    ObjectMapper mapper = new ObjectMapper();
    String sql = "INSERT INTO `uploads` (`account`, `file`, `lenght`, `data`,`enddir`, `metadata`, `status`,`starttime`) "
            + "VALUES (?,?,?,?,?,?,?,?)";
    prest = c.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS);
    prest.setInt(1, metadata.getAccount());
    prest.setString(2, file.getAbsolutePath());
    prest.setLong(3, file.length());//from   w  ww.  j  a  v a 2  s  . co  m
    prest.setString(4, mapper.writeValueAsString(data));
    prest.setString(5, metadata.getEndDirectory());
    prest.setString(6, mapper.writeValueAsString(metadata));
    prest.setString(7, UploadManager.Status.NOT_STARTED.toString());
    if (startAt == null) {
        prest.setString(8, "");
    } else {
        prest.setDate(8, new java.sql.Date(startAt.getTime()));
    }
    prest.execute();
    ResultSet rs = prest.getGeneratedKeys();
    prest.close();
    if (rs.next()) {
        int id = rs.getInt(1);
        rs.close();
        return id;
    } else {
        return -1;
    }
}

From source file:hr.fer.zemris.vhdllab.dao.impl.ProjectDaoImplTest.java

private void setupProject(final Project project) {
    String query = createInsertStatement("projects", "id, version, name, user_id", "null, 0, ?, ?");
    getJdbcTemplate().execute(query, new PreparedStatementCallback() {
        @Override/*  www  .  ja  va 2 s . com*/
        public Object doInPreparedStatement(PreparedStatement ps) throws SQLException, DataAccessException {
            ps.setString(1, project.getName());
            ps.setString(2, project.getUserId());
            return ps.execute();
        }
    });
}

From source file:com.l2jfree.gameserver.instancemanager.FriendListManager.java

public synchronized boolean remove(Integer objId1, Integer objId2) {
    boolean modified = false;

    modified |= _friends.containsKey(objId1) && _friends.get(objId1).remove(objId2);
    modified |= _friends.containsKey(objId2) && _friends.get(objId2).remove(objId1);

    if (!modified)
        return false;

    Connection con = null;/*from www  .j a va2 s .  co m*/
    try {
        con = L2DatabaseFactory.getInstance().getConnection();

        PreparedStatement statement = con.prepareStatement(DELETE_QUERY);
        statement.setInt(1, objId1);
        statement.setInt(2, objId2);
        statement.setInt(3, objId2);
        statement.setInt(4, objId1);

        statement.execute();

        statement.close();
    } catch (SQLException e) {
        _log.warn("", e);
    } finally {
        L2DatabaseFactory.close(con);
    }

    return true;
}

From source file:me.redstarstar.rdfx.duty.dao.jdbc.ScheduleJdbcDao.java

@Override
public void save(Schedule schedule) {
    jdbcTemplate.execute("INSERT INTO schedule (parent_id, week, activity_date, create_date, update_date) "
            + "VALUES (?, ?, ?, NOW(), NOW());", (PreparedStatement preparedStatement) -> {
                preparedStatement.setLong(1, schedule.getParentId());
                preparedStatement.setInt(2, schedule.getWeek());
                preparedStatement.setDate(3, Date.valueOf(schedule.getActivityDate()));
                preparedStatement.execute();
                return null;
            });//from  w ww.  j  av  a 2  s. c om
}