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:com.google.flightmap.parsing.faa.afd.AfdCommParser.java

private void initAirportCommTable() throws SQLException {
    Statement stat = dbConn.createStatement();
    stat.executeUpdate("DROP TABLE IF EXISTS airport_comm");
    stat.executeUpdate("DROP INDEX IF EXISTS airport_comm_airport_id_index;");
    stat.executeUpdate(/*w  w w  . ja  va  2 s  .  c  o  m*/
            "CREATE TABLE airport_comm (" + "_id INTEGER PRIMARY KEY ASC, " + "airport_id INTEGER NOT NULL, "
                    + "identifier TEXT NOT NULL, " + "frequency TEXT NOT NULL, " + "remarks TEXT);");
    stat.executeUpdate("CREATE INDEX airport_comm_airport_id_index ON " + "airport_comm (airport_id)");
    stat.close();

}

From source file:JDBCExecutor.java

public void executeUpdate(String sql) throws SQLException {
    LOG("Executing query: " + sql);
    try (Connection connection = getConnection()) {
        Statement stmt = connection.createStatement();
        LOG("\t Time taken to create statement : ");

        stmt.executeUpdate(sql);
        LOG("\t Time taken to execute query : ");
    }//from  ww  w .  j av a  2  s  .c o  m
}

From source file:com.oracle.tutorial.jdbc.ProductInformationTable.java

public void createTable() throws SQLException {
    String createString = "create table PRODUCT_INFORMATION" + "  (COF_NAME varchar(32) NOT NULL,"
            + "  INFO clob NOT NULL," + "  FOREIGN KEY (COF_NAME) REFERENCES COFFEES (COF_NAME))";

    Statement stmt = null;
    try {//from w  w w .j  a v  a 2 s . c o m
        stmt = con.createStatement();
        stmt.executeUpdate(createString);
    } catch (SQLException e) {
        JDBCTutorialUtilities.printSQLException(e);
    } finally {
        if (stmt != null) {
            stmt.close();
        }
    }
}

From source file:dbcount.DbCountInitializeJob.java

private void dropTables(final Connection conn, final boolean useView) {
    final String dropAccess = "DROP TABLE Access";
    final String dropPageview = "DROP TABLE Pageview";
    try {/*  www.  ja va  2 s . co m*/
        Statement st = conn.createStatement();
        st.executeUpdate(dropAccess);
        if (!useView) {
            st.executeUpdate(dropPageview);
        }
        conn.commit();
        st.close();
    } catch (SQLException ex) {// ignore
        try {
            conn.rollback();
        } catch (SQLException e) {
            ;
        }
    }
}

From source file:libepg.util.db.JDBCAccessorTest.java

/**
 * Test of getConnection method, of class JDBCAccessor.
 *
 */// w ww  .  ja  va  2 s  . c o m
@Test
public void testGetCon() {
    try {

        LOG.info("getCon");
        JDBCAccessor instance = JDBCAccessor.getInstance();
        String url = "jdbc:sqlite::memory:";
        instance.connect(url);
        java.sql.Connection result = instance.getConnection();
        assertNotNull(result);
        LOG.debug("Connected.");

        Statement stmt = result.createStatement();
        //?
        stmt.executeUpdate("create table test1( name string, age integer )");
        LOG.debug("Made table.");

        //?
        String nameVal = "jjj888???";
        int ageVal = 778;
        String sql1 = "insert into test1 values (?,?)";
        PreparedStatement pstmt1 = result.prepareStatement(sql1);
        pstmt1.setString(1, nameVal);
        pstmt1.setInt(2, ageVal);
        pstmt1.executeUpdate();
        LOG.debug("Inserted.");

        //??
        String sql2 = "select * from test1 where name=? and age=?";
        PreparedStatement pstmt2 = result.prepareStatement(sql2);
        pstmt2.setString(1, nameVal);
        pstmt2.setInt(2, ageVal);
        ResultSet rs = pstmt2.executeQuery();
        while (rs.next()) {
            String str1 = rs.getString("name");
            int int2 = rs.getInt("age");
            System.out.println(str1);
            System.out.println(int2);
            assertEquals(nameVal, str1);
            assertEquals(ageVal, int2);
        }
        LOG.debug("Got data.");

    } catch (SQLException ex) {
        LOG.fatal(ex);
        fail();
    } finally {
        JDBCAccessor.getInstance().close();
    }
}

From source file:org.web4thejob.module.JobletInstallerImpl.java

@Override
@SuppressWarnings("unchecked")
public <E extends Exception> List<E> install(List<Joblet> joblets) {
    List<E> exceptions = new ArrayList<E>();

    try {//w  w w. jav  a2s  .  c  o m

        final Configuration configuration = new Configuration();
        configuration.setProperty(AvailableSettings.DIALECT,
                connInfo.getProperty(DatasourceProperties.DIALECT));
        configuration.setProperty(AvailableSettings.DRIVER, connInfo.getProperty(DatasourceProperties.DRIVER));
        configuration.setProperty(AvailableSettings.URL, connInfo.getProperty(DatasourceProperties.URL));
        configuration.setProperty(AvailableSettings.USER, connInfo.getProperty(DatasourceProperties.USER));
        configuration.setProperty(AvailableSettings.PASS, connInfo.getProperty(DatasourceProperties.PASSWORD));

        final ServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder()
                .applySettings(configuration.getProperties()).build();

        if (StringUtils.hasText(connInfo.getProperty(DatasourceProperties.SCHEMA_SYNTAX))) {
            String schemaSyntax = connInfo.getProperty(DatasourceProperties.SCHEMA_SYNTAX);
            Connection connection = serviceRegistry.getService(ConnectionProvider.class).getConnection();

            for (Joblet joblet : joblets) {
                for (String schema : joblet.getSchemas()) {
                    Statement statement = connection.createStatement();
                    statement.executeUpdate(schemaSyntax.replace("%s", schema));
                    statement.close();
                }
            }

            if (!connection.getAutoCommit()) {
                connection.commit();
            }
        }

        for (Joblet joblet : joblets) {
            for (Resource resource : joblet.getResources()) {
                configuration.addInputStream(resource.getInputStream());
            }
        }

        SchemaExport schemaExport = new SchemaExport(serviceRegistry, configuration);
        schemaExport.execute(Target.EXPORT, SchemaExport.Type.CREATE);
        exceptions.addAll(schemaExport.getExceptions());

    } catch (Exception e) {
        exceptions.add((E) e);
    }

    return exceptions;

}

From source file:DatabaseTest.java

private void createSchema() throws Exception {
    Statement statement = dbConn.createStatement();
    statement.executeUpdate("create table if not exists PERSON (" + "ID int identity primary key,"
            + "NAME varchar(100)," + "LAST_NAME varchar(100)," + "BORN DATETIME," + "STARTED DATE)");
    statement.close();//from   w w w  .  j a  v a 2  s  . c  o  m
}

From source file:com.bc.fiduceo.db.AbstractDriver.java

@Override
public void initialize() throws SQLException {
    Statement statement = connection.createStatement();
    statement.executeUpdate("CREATE TABLE SATELLITE_OBSERVATION (ID INT AUTO_INCREMENT PRIMARY KEY, "
            + "StartDate TIMESTAMP," + "StopDate TIMESTAMP," + "NodeType TINYINT," + "GeoBounds GEOMETRY, "
            + "SensorId INT," + "Version VARCHAR(16)," + "DataFile VARCHAR(256))");

    statement = connection.createStatement();
    statement.executeUpdate("CREATE TABLE SENSOR (ID INT AUTO_INCREMENT PRIMARY KEY, " + "Name VARCHAR(64))");

    statement = connection.createStatement();
    statement.executeUpdate("CREATE TABLE TIMEAXIS (ID INT AUTO_INCREMENT PRIMARY KEY, " + "ObservationId INT,"
            + "Axis GEOMETRY," + "StartTime TIMESTAMP, " + "StopTime TIMESTAMP, "
            + "FOREIGN KEY (ObservationId) REFERENCES SATELLITE_OBSERVATION(ID))");
}

From source file:dbcount.DbCountInitializeJob.java

private void createTables(final Connection conn, final boolean useView) throws SQLException {
    final String createAccess = "CREATE TABLE " + "Access(url VARCHAR(100) NOT NULL,"
            + " referrer VARCHAR(100)," + " time BIGINT NOT NULL," + " PRIMARY KEY (url, time))";
    final String createPageview = "CREATE TABLE " + "Pageview(url VARCHAR(100) NOT NULL,"
            + " pageview BIGINT NOT NULL," + " PRIMARY KEY (url))";

    Statement st = conn.createStatement();
    try {//from  www  .j a  v a  2  s  .  co  m
        st.executeUpdate(createAccess);
        if (!useView) {
            st.executeUpdate(createPageview);
        }
        conn.commit();
    } finally {
        st.close();
    }
}

From source file:libepg.ts.aligner.Alligner2.java

public synchronized List<TsPacketParcel> getAllignedPackets() {
    JDBCAccessor ac = JDBCAccessor.getInstance();
    try {//w  w  w . jav  a 2  s  .  c  om
        ac.connect(AboutDB.URL);
        Connection conn = ac.getConnection();

        Statement stmt = conn.createStatement();
        //?
        stmt.executeUpdate(CRATE_TABLE);

        //?PID??????
        for (TsPacket tsp : this.packets) {
            //                System.out.println(Integer.toHexString(tsp.getPid()));
            if (tsp.getPid() == this.getPid()) {
                PreparedStatement insertStatement = conn.prepareStatement(INSERT_SQL);
                insertStatement.setInt(1, tsp.getPid());
                insertStatement.setInt(2, tsp.getContinuity_counter());
                insertStatement.setInt(3, 0);
                insertStatement.setBytes(4, tsp.getData());
                insertStatement.executeUpdate();
            }
        }

        debug_dump_table(conn);

        //            //
        //            LinkedList<TsPacketParcel> temp = new LinkedList<>();
        //            for (TsPacket tsp : this.packets) {
        //
        //                //??????0
        //                if (tsp.getAdaptation_field_control() == TsPacket.ADAPTATION_FIELD_CONTROL.ONLY_ADAPTATION_FIELD) {
        //                    if (tsp.getContinuity_counter() == 0) {
        //                        temp.add(new TsPacketParcel(tsp, TsPacketParcel.MISSING_PACKET_FLAG.NOT_MISSING));
        //                    } else if (LOG.isWarnEnabled()) {
        //                        LOG.warn("???0????????");
        //                        LOG.warn(tsp);
        //                    }
        //                }
        //
        //                if (LOG.isTraceEnabled()) {
        //                    LOG.trace("????");
        //                }
        //                if (temp.contains(tsp)) {
        //
        //                }
        //            }
    } catch (SQLException ex) {
        LOG.fatal(ex);
    } finally {
        ac.close();
    }
    return null;
}