Example usage for java.sql Statement executeUpdate

List of usage examples for java.sql Statement executeUpdate

Introduction

In this page you can find the example usage for java.sql Statement executeUpdate.

Prototype

int executeUpdate(String sql) throws SQLException;

Source Link

Document

Executes the given SQL statement, which may be an INSERT, UPDATE, or DELETE statement or an SQL statement that returns nothing, such as an SQL DDL statement.

Usage

From source file:Main.java

public static void createXMLTable(Statement stmt) throws SQLException {
    String streamingDataSql = "CREATE TABLE XML_Data (id INTEGER, Data CLOB)";
    // stmt.executeUpdate("DROP TABLE XML_Data");
    stmt.executeUpdate(streamingDataSql);
}

From source file:de.dakror.virtualhub.server.DBManager.java

public static void init() {
    try {//from   w w w .ja  va  2 s .c om
        database = new File(Server.dir, "virtualhub.db");
        database.createNewFile();

        Class.forName("org.sqlite.JDBC");
        connection = DriverManager.getConnection("jdbc:sqlite:" + database.getPath().replace("\\", "/"));

        Statement s = connection.createStatement();
        s.executeUpdate(
                "CREATE TABLE IF NOT EXISTS ETICETS(PATH varchar(500) NOT NULL PRIMARY KEY, CATALOG varchar(100), ETICET INT)");
        s.executeUpdate(
                "CREATE TABLE IF NOT EXISTS TAGS(PATH varchar(500) NOT NULL PRIMARY KEY, CATALOG varchar(100), TAGS TEXT)");
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:gridool.mapred.db.DBReduceJob.java

public static void createView(final String dstDbUrl, final String createTables, final String createView,
        final DBMapReduceJobConf jobConf) throws SQLException {
    final Connection conn;
    try {//from  w  ww  . ja  v  a  2  s  .co  m
        conn = jobConf.getConnection(dstDbUrl, true);
    } catch (ClassNotFoundException e) {
        throw new SQLException(e);
    }
    try {
        Statement st = conn.createStatement();
        st.executeUpdate(createTables);
        st.executeUpdate(createView);
        st.close();
        conn.commit();
        if (LOG.isInfoEnabled()) {
            LOG.info(createTables);
            LOG.info(createView);
        }
    } catch (SQLException sqle) {
        conn.rollback();
        throw sqle;
    } finally {
        conn.close();
    }
}

From source file:net.big_oh.common.jdbc.JdbcProxyExerciser.java

private static void exerciseRegularInsert(Connection con) throws SQLException {
    logger.info(StringUtils.center("exercise regular insert", 100, "-"));

    Statement stmt = null;
    try {//w ww .  ja v a 2  s .  c  o  m
        stmt = con.createStatement();
        stmt.executeUpdate("INSERT INTO TEST_TABLE VALUES ( 'value1' )");
    } finally {
        DbUtils.closeQuietly(stmt);
    }
}

From source file:net.big_oh.common.jdbc.JdbcProxyExerciser.java

private static void cleanOutTestTable(Connection con) throws SQLException {
    logger.info(StringUtils.center("clean out the test table", 100, "-"));

    Statement stmt = null;
    try {/*  ww  w. j  a v  a  2s  .  com*/
        stmt = con.createStatement();
        stmt.executeUpdate("TRUNCATE TABLE TEST_TABLE");
    } finally {
        DbUtils.closeQuietly(stmt);
    }
}

From source file:com.p6spy.engine.spy.P6TestUtil.java

public static int executeUpdate(Connection connection, String query) throws SQLException {
    Statement stmt = null;
    try {//from   w w  w.  j  av  a  2 s .  c  om
        stmt = connection.createStatement();
        return stmt.executeUpdate(query);
    } finally {
        if (stmt != null)
            try {
                stmt.close();
            } catch (Exception e) {
            }
    }
}

From source file:com.data2semantics.yasgui.server.db.ConnectionFactory.java

/**
 * Create database/*from w w  w . j  av  a 2 s  . co  m*/
 * @param connect
 * @param dbName
 * @throws SQLException
 */
private static void createDatabase(Connection connect, String dbName) throws SQLException {
    Statement statement = connect.createStatement();
    statement.executeUpdate(
            "CREATE DATABASE `" + dbName + "` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci");
    statement.close();
}

From source file:com.example.mydtapp.JdbcInputAppTest.java

public static void cleanTable() {
    try {//from www  . ja v a 2 s. co m
        Connection con = DriverManager.getConnection(URL);
        Statement stmt = con.createStatement();
        String cleanTable = "delete from " + TABLE_NAME;
        stmt.executeUpdate(cleanTable);
    } catch (SQLException e) {
        throw new RuntimeException(e);
    }
}

From source file:com.flexive.ejb.beans.structure.FxStructureUtils.java

/**
 * Remove all properties that are no longer referenced
 *
 * @param con a valid connection/*from   www.j a  va2 s  .  com*/
 * @throws java.sql.SQLException on errors
 */
public static void removeOrphanedProperties(Connection con) throws SQLException {
    Statement stmt = null;
    try {
        stmt = con.createStatement();
        stmt.executeUpdate(
                "DELETE FROM " + TBL_STRUCT_PROPERTIES + ML + " WHERE ID NOT IN(SELECT DISTINCT APROPERTY FROM "
                        + TBL_STRUCT_ASSIGNMENTS + " WHERE APROPERTY IS NOT NULL)");
        stmt.executeUpdate("DELETE FROM " + TBL_STRUCT_PROPERTY_OPTIONS
                + " WHERE ID NOT IN(SELECT DISTINCT APROPERTY FROM " + TBL_STRUCT_ASSIGNMENTS
                + " WHERE APROPERTY IS NOT NULL)");
        int removed = stmt.executeUpdate(
                "DELETE FROM " + TBL_STRUCT_PROPERTIES + " WHERE ID NOT IN(SELECT DISTINCT APROPERTY FROM "
                        + TBL_STRUCT_ASSIGNMENTS + " WHERE APROPERTY IS NOT NULL)");
        if (removed > 0)
            LOG.info(removed + " orphaned properties removed.");
    } catch (SQLException e) {
        LOG.warn("Some orphaned properties could not be removed yet.");
    } finally {
        if (stmt != null)
            stmt.close();
    }
}

From source file:com.flexive.ejb.beans.structure.FxStructureUtils.java

/**
 * Remove all groups that are no longer referenced
 *
 * @param con a valid connection/*from  w ww.  j a  v a  2 s .c o  m*/
 * @throws java.sql.SQLException on errors
 */
public static void removeOrphanedGroups(Connection con) throws SQLException {
    Statement stmt = null;
    try {
        stmt = con.createStatement();
        stmt.executeUpdate(
                "DELETE FROM " + TBL_STRUCT_GROUPS + ML + " WHERE ID NOT IN(SELECT DISTINCT AGROUP FROM "
                        + TBL_STRUCT_ASSIGNMENTS + " WHERE AGROUP IS NOT NULL)");
        stmt.executeUpdate(
                "DELETE FROM " + TBL_STRUCT_GROUP_OPTIONS + " WHERE ID NOT IN(SELECT DISTINCT AGROUP FROM "
                        + TBL_STRUCT_ASSIGNMENTS + " WHERE AGROUP IS NOT NULL)");
        int removed = stmt.executeUpdate(
                "DELETE FROM " + TBL_STRUCT_GROUPS + " WHERE ID NOT IN(SELECT DISTINCT AGROUP FROM "
                        + TBL_STRUCT_ASSIGNMENTS + " WHERE AGROUP IS NOT NULL)");
        if (removed > 0)
            LOG.info(removed + " orphaned groups removed.");
    } catch (SQLException e) {
        LOG.warn("Some orphaned groups could not be removed yet.");
    } finally {
        if (stmt != null)
            stmt.close();
    }
}