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:Phnbk.java

private void createTables(Statement statement) throws SQLException {
    String use = "USE user_info";
    statement.executeUpdate(use);

    String crtTabl = "CREATE TABLE phone_book " + "(id INTEGER NOT NULL AUTO_INCREMENT, "
            + "parent_id INTEGER NOT NULL, " + " name VARCHAR(255), " + " address VARCHAR(255), "
            + " PRIMARY KEY ( id ))";

    statement.executeUpdate(crtTabl);//from   w ww . ja  va 2 s.  c om

    crtTabl = "CREATE TABLE mobile_number " + "(id INT(11), " + " number INT(11), "
            + " PRIMARY KEY ( number ))";

    statement.executeUpdate(crtTabl);

    crtTabl = "CREATE TABLE home_number " + "(id INT(11), " + " number INT(11), " + " PRIMARY KEY ( number ))";

    statement.executeUpdate(crtTabl);

    crtTabl = "CREATE TABLE work_number " + "(id INT(11), " + " number INT(11), " + " PRIMARY KEY ( number ))";

    statement.executeUpdate(crtTabl);

}

From source file:com.bt.aloha.testing.DbTestCase.java

protected synchronized int update(String expression) throws SQLException {
    Statement st = connection.createStatement();
    try {/*from  ww w  .  jav a2  s  .co m*/
        return st.executeUpdate(expression);
    } finally {
        st.close();
    }
}

From source file:geocodingissues.Main.java

public void insertValues(int id, String street_no, String street) {
    //System.out.println("id = " + Integer.toString(id));
    //System.out.println("street_no = " + street_no);
    //System.out.println("street = " + street);
    //System.out.println("neighborhood = " + neighborhood);
    try {//from  w  w w  .ja v  a2  s  .c o  m
        Statement s = connection.createStatement();

        s.executeUpdate("UPDATE issues " + "SET street_no = " + "'" + street_no + "', " + "street = " + "'"
                + street + "' " + "WHERE id = " + Integer.toString(id));
    } catch (Exception e) {
        System.out.println("Problem in updating the database street");
    }
}

From source file:com.pankaj.GenericResource.java

/**
 *
 * @param obj//ww w .j a  v a2  s  .  com
 * @return
 * @throws SQLException
 */
@POST
@Path("/products")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)

public Response createProduct(String str) throws SQLException, ParseException {

    JSONParser parser = new JSONParser();
    JSONObject json = (JSONObject) parser.parse(str);

    Object id = json.get("id");
    String productid = id.toString();
    int Id = Integer.parseInt(productid);
    Object name = json.get("name");
    String productname = name.toString();
    Object description = json.get("description");
    String productdescription = description.toString();
    Object quantity = json.get("quantity");
    String productquantity = quantity.toString();
    int Qnt = Integer.parseInt(productquantity);
    Statement smt = conn.createStatement();
    smt.executeUpdate("INSERT INTO product VALUES ('" + Id + "','" + productname + "','" + productdescription
            + "','" + Qnt + "' )");
    return Response.status(Status.CREATED).build();
}

From source file:atg.tools.dynunit.test.util.RepositoryManager.java

/**
 * @throws SQLException//from w  ww . j a va 2  s  . c  o m
 */
private void createIdGeneratorTables() throws SQLException {

    log.info("Re-creating (drop and create) DAS_ID_GENERATOR");

    final Statement statement = dataSource.getConnection().createStatement();
    try {
        statement.executeUpdate("DROP TABLE DAS_ID_GENERATOR");
    } catch (SQLException e) {
        log.catching(e);
        // just try drop any existing DAS_ID_GENERATOR if desired
    }
    // create new DAS_ID_GENERATOR
    statement.executeUpdate("CREATE TABLE DAS_ID_GENERATOR(ID_SPACE_NAME VARCHAR(60) NOT NULL, "
            + "SEED NUMERIC(19, 0) NOT NULL, BATCH_SIZE INTEGER NOT NULL,   "
            + "PREFIX VARCHAR(10) DEFAULT NULL, SUFFIX VARCHAR(10) DEFAULT NULL, "
            + "PRIMARY KEY(ID_SPACE_NAME))");
    statement.close();
}

From source file:jp.tricreo.schemagenerator.domain.model.impl.SqlActionImpl.java

@Override
public void execute(ActionContext actionContext) {
    Validate.notNull(actionContext);/*w w w.j av  a 2 s.  co m*/
    Statement statement = null;
    try {
        statement = actionContext.getConnection().createStatement();
        if (statement.executeUpdate(sql) > 0) {
            actionContext.getLogger().debug("sql = " + sql);
        }
    } catch (SQLException e) {
        throw new SQLRuntimeException(e);
    } finally {
        CloseableUtil.close(statement);
    }
}

From source file:atg.test.util.RepositoryManager.java

/**
 * //from  w ww .  j  av a 2  s.c om
 * @throws SQLException
 */
private void createIdGeneratorTables() throws SQLException {

    log.info("Re-creating (drop and create) DAS_ID_GENERATOR");

    final Statement statement = dataSource.getConnection().createStatement();
    try {
        statement.executeUpdate("DROP TABLE DAS_ID_GENERATOR");
    } catch (SQLException e) {
        // just try drop any existing DAS_ID_GENERATOR if desired
    }
    // create new DAS_ID_GENERATOR
    statement.executeUpdate("CREATE TABLE DAS_ID_GENERATOR(ID_SPACE_NAME VARCHAR(60) NOT NULL, "
            + "SEED NUMERIC(19, 0) NOT NULL, BATCH_SIZE INTEGER NOT NULL,   "
            + "PREFIX VARCHAR(10) DEFAULT NULL, SUFFIX VARCHAR(10) DEFAULT NULL, "
            + "PRIMARY KEY(ID_SPACE_NAME))");
    statement.close();
}

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

public void createTable() throws SQLException {
    String createString = "create table SUPPLIERS " + "(SUP_ID integer NOT NULL, "
            + "SUP_NAME varchar(40) NOT NULL, " + "STREET varchar(40) NOT NULL, "
            + "CITY varchar(20) NOT NULL, " + "STATE char(2) NOT NULL, " + "ZIP char(5), "
            + "PRIMARY KEY (SUP_ID))";
    Statement stmt = null;
    try {//from  www .  ja v a2  s  . co  m
        stmt = con.createStatement();
        stmt.executeUpdate(createString);
    } catch (SQLException e) {
        JDBCTutorialUtilities.printSQLException(e);
    } finally {
        if (stmt != null) {
            stmt.close();
        }
    }
}

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

public void populateTable() throws SQLException {
    Statement stmt = null;
    try {/*from   ww w .  ja v a  2 s  .c o m*/
        stmt = con.createStatement();
        stmt.executeUpdate("insert into SUPPLIERS " + "values(49, 'Superior Coffee', '1 Party Place', "
                + "'Mendocino', 'CA', '95460')");
        stmt.executeUpdate("insert into SUPPLIERS " + "values(101, 'Acme, Inc.', '99 Market Street', "
                + "'Groundsville', 'CA', '95199')");
        stmt.executeUpdate("insert into SUPPLIERS " + "values(150, 'The High Ground', '100 Coffee Lane', "
                + "'Meadows', 'CA', '93966')");
    } catch (SQLException e) {
        JDBCTutorialUtilities.printSQLException(e);
    } finally {
        if (stmt != null) {
            stmt.close();
        }
    }
}

From source file:hu.bme.mit.trainbenchmark.benchmark.sqlite.driver.SQLiteDriver.java

@Override
public void read(final String modelPath) throws IOException, InterruptedException, SQLException {
    final File modelFile = new File(modelPath);
    if (!modelFile.exists()) {
        throw new IOException("Model does not exist: " + modelPath);
    }//from   w w  w .  j  av  a 2 s . com

    connection = DriverManager.getConnection("jdbc:sqlite::memory:");
    final Statement statement = connection.createStatement();
    statement.setQueryTimeout(3600);

    final String sql = FileUtils.readFileToString(new File(modelPath));
    statement.executeUpdate(sql);

    // create temporary table (used by the transformations)
    final PreparedStatement createStatement = connection
            .prepareStatement("CREATE TEMP TABLE IF NOT EXISTS Variables (Name TEXT PRIMARY KEY, Value LONG);");
    createStatement.execute();
}