當前位置: 首頁>>代碼示例>>Java>>正文


Java Statement.executeUpdate方法代碼示例

本文整理匯總了Java中java.sql.Statement.executeUpdate方法的典型用法代碼示例。如果您正苦於以下問題:Java Statement.executeUpdate方法的具體用法?Java Statement.executeUpdate怎麽用?Java Statement.executeUpdate使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.sql.Statement的用法示例。


在下文中一共展示了Statement.executeUpdate方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: updateUserId

import java.sql.Statement; //導入方法依賴的package包/類
void updateUserId() throws FileNotFoundException, IOException, SQLException {
    String adminUserId = getProperty(ssoPropertyFile, ADMIN_USER_ID);
    Connection conn = null;
    Statement stmt = null;
    try {
        conn = getConnetion();
        stmt = conn.createStatement();
        stmt.executeUpdate(String.format(
                "UPDATE %s SET userid = '%s' WHERE tkey = 1000",
                TABLE_NAME, adminUserId));
        stmt.close();
        conn.close();

    } finally {
        closeStatement(stmt);
        closeConnection(conn);

    }
}
 
開發者ID:servicecatalog,項目名稱:oscm,代碼行數:20,代碼來源:SSOPropertyImport.java

示例2: initInbox

import java.sql.Statement; //導入方法依賴的package包/類
private void initInbox() throws SQLException, ClassNotFoundException {
    String sql1 = "DROP TABLE IF EXISTS inbox";
    String sql2 = "CREATE TABLE inbox " +
            "(msgId Varchar(100) NOT NULL, " +
            "threadId Varchar(100) NOT NULL, " +
            "historyId Varchar(100) NOT NULL, " +
            "sentTo VARCHAR(1000) NOT NULL, " +
            "recievedFrom Varchar(1000) NOT NULL, " +
            "mailDate Varchar(1000) NOT NULL," +
            "subject Varchar(10000) , " +
            "isUnread int NOT NULL);";
    Statement statement = h2DBConnection.getConnection().createStatement();
    statement.executeUpdate(sql1);
    statement.executeUpdate(sql2);
    statement.close();
}
 
開發者ID:ashoknailwal,項目名稱:desktop-gmail-client,代碼行數:17,代碼來源:InitDbTables.java

示例3: dropExistingSchema

import java.sql.Statement; //導入方法依賴的package包/類
/**
 * Delete any existing tables.
 */
public void dropExistingSchema() throws SQLException {
  ConnManager mgr = getManager();
  String [] tables = mgr.listTables();
  if (null != tables) {
    Connection conn = mgr.getConnection();
    for (String table : tables) {
      Statement s = conn.createStatement();
      try {
        s.executeUpdate("DROP TABLE \"" + table + "\"");
        conn.commit();
      } finally {
        s.close();
      }
    }
  }
}
 
開發者ID:aliyun,項目名稱:aliyun-maxcompute-data-collectors,代碼行數:20,代碼來源:HsqldbTestServer.java

示例4: AgregarEspecialidad

import java.sql.Statement; //導入方法依賴的package包/類
public String AgregarEspecialidad(String cod, String especialidad) {
    Conexion nconexion = new Conexion();  //objeto de la clase conexion
    Connection conex; 
   
    try
    {
        nconexion.Conectar(); // ejecuta el metodo conectar de la clase conexion el que contiene la direccion de la base de datos 
        conex = nconexion.getConexion();  //aca se retorna la conexion que se obtuvo
        Statement comando = conex.createStatement(); //comando para poder ejecutar executeUpdate
        
        //EJECUTAR LA CONSULTA DE INSERCION
        
        comando.executeUpdate("insert into especialidades() values('0','"+cod+"','"+especialidad+"')");

        conex.close();
        return "Especialidad agregada exitosamente";
    
    }
    
    catch(Exception e)
    {
        
        return "Ha ocurrido un error al agregar una especialidad "+e;
    }

}
 
開發者ID:JuanJoseFJ,項目名稱:ProyectoPacientes,代碼行數:27,代碼來源:AsignarEsp.java

示例5: executeUpdate

import java.sql.Statement; //導入方法依賴的package包/類
public final int executeUpdate(String sql, Object... args) {
    if (!isConnected()) {
        return -1;
    }
    String temp = null;
    try {
        temp = (args != null && args.length != 0) ? String.format(sql, args) : sql;
        if (DEBUG_SQL) {
            System.out.println(temp);
        }
        final Statement statement = createStatement();
        final int result = statement.executeUpdate(temp);
        statement.close();
        return result;
    } catch (Exception ex) {
        System.err.println("Database: Executing update error");
        if (DEBUG) {
            System.err.println("SQL: " + temp);
        }
        ex.printStackTrace();
        return -1;
    }
}
 
開發者ID:Panzer1119,項目名稱:Supreme-Bot,代碼行數:24,代碼來源:Database.java

示例6: manualTestBug22750465SomeReadWriteOperations

import java.sql.Statement; //導入方法依賴的package包/類
private void manualTestBug22750465SomeReadWriteOperations(Connection testConn) throws Exception {
    Statement stmt = testConn.createStatement();
    try {
        stmt.executeUpdate("CREATE TABLE IF NOT EXISTS testBug22750465 (id INT)");
        stmt.executeUpdate("INSERT INTO testBug22750465 VALUES (1)");
        ResultSet rs = stmt.executeQuery("SELECT * FROM testBug22750465");
        assertTrue(rs.next());
    } finally {
        stmt.executeUpdate("DROP TABLE IF EXISTS testBug22750465");
        stmt.close();
    }
}
 
開發者ID:Jugendhackt,項目名稱:OpenVertretung,代碼行數:13,代碼來源:TestRegressions.java

示例7: upgrade

import java.sql.Statement; //導入方法依賴的package包/類
/**
 * Perform upgrade.
 */
public void upgrade(final Connection conn, final int upgradeToVersion) throws SQLException {
  final boolean savedAutoCommit = conn.getAutoCommit();
  Statement st = null; // NOPMD
  PreparedStatement pstmt = null; // NOPMD
  try {
    // create statement
    conn.setAutoCommit(true);
    st = conn.createStatement();

    log.debug("Updating version");
    st.executeUpdate("update SYSTEM_PROPERTY set VALUE = '" + upgraderVersion() + "' where NAME = 'parabuild.schema.version' ");

    // finish
    conn.commit();

    // request post-startup config manager action
    System.setProperty(SystemConstants.SYSTEM_PROPERTY_INIT_ADVANCED_SETTINGS, "true");
  } finally {
    IoUtils.closeHard(pstmt);
    IoUtils.closeHard(st);
    conn.setAutoCommit(savedAutoCommit);
  }
}
 
開發者ID:parabuild-ci,項目名稱:parabuild-ci,代碼行數:27,代碼來源:UpgraderToVersion17.java

示例8: populateTable

import java.sql.Statement; //導入方法依賴的package包/類
private void populateTable(String tableName) throws SQLException {
  Statement statement = conn.createStatement();
  try {
    statement.executeUpdate("INSERT INTO " + tableName
        + " VALUES(1,'Aaron','2009-05-14',1000000.00,TRUE,'engineering')");
    statement.executeUpdate("INSERT INTO " + tableName
        + " VALUES(2,'Bob','2009-04-20',400.00,TRUE,'sales')");
    statement.executeUpdate("INSERT INTO " + tableName
        + " VALUES(3,'Fred','2009-01-23',15.00,FALSE,'marketing')");
    conn.commit();
  } finally {
    statement.close();
  }
}
 
開發者ID:aliyun,項目名稱:aliyun-maxcompute-data-collectors,代碼行數:15,代碼來源:NetezzaImportManualTest.java

示例9: setUp

import java.sql.Statement; //導入方法依賴的package包/類
@Override
public void setUp() throws Exception {
    if (this.isSetForFabricTest) {
        this.conn = (FabricMySQLConnection) this.ds.getConnection(this.username, this.password);

        // create table globally
        this.conn.setServerGroupName("fabric_test1_global");
        Statement stmt = this.conn.createStatement();
        stmt.executeUpdate("drop table if exists employees");
        stmt.executeUpdate("create table employees (emp_no INT PRIMARY KEY, first_name CHAR(40), last_name CHAR(40))");
        this.conn.clearServerSelectionCriteria();
    }
}
 
開發者ID:Jugendhackt,項目名稱:OpenVertretung,代碼行數:14,代碼來源:TestHashSharding.java

示例10: deleteXBRecord

import java.sql.Statement; //導入方法依賴的package包/類
/**
 * This method demonstrates the bug in cascading deletes. Before this method,
 * the CA table has 12 records. After, it should have 9, but instead it has
 * 0.
 */
private static void deleteXBRecord(Connection con) throws SQLException {

    Statement stmt = con.createStatement();

    stmt.executeUpdate(
        "DELETE FROM XB WHERE LSACONXB = 'LEAA' AND EIACODXA = 'T850' AND LCNTYPXB = 'P' AND ALTLCNXB = '00'");
    stmt.close();
}
 
開發者ID:Julien35,項目名稱:dev-courses,代碼行數:14,代碼來源:TestCascade.java

示例11: testRefreshTable

import java.sql.Statement; //導入方法依賴的package包/類
public void testRefreshTable() throws Exception {
    Table fooTable = metadata.getDefaultSchema().getTable("FOO");
    assertNames(Arrays.asList("ID", "FOO_NAME"), fooTable.getColumns());
    Statement stmt = conn.createStatement();
    stmt.executeUpdate("ALTER TABLE FOO ADD NEW_COLUMN VARCHAR(16)");
    stmt.close();
    fooTable.refresh();
    assertNames(Arrays.asList("ID", "FOO_NAME", "NEW_COLUMN"), fooTable.getColumns());
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:10,代碼來源:JDBCMetadataDerbyTest.java

示例12: sendFileName

import java.sql.Statement; //導入方法依賴的package包/類
public boolean sendFileName(String newName, String zipName) throws SQLException{
	Statement st = connection.createStatement();
	int response;
	String sql = ("UPDATE CTP "
			+ "SET zipName = " + "\"" + zipName + "\"" 
			+ " WHERE nameAnon = " + "\"" + newName + "\""
			+ ";");
	response = st.executeUpdate(sql);		
	return response > 0;
}
 
開發者ID:anousv,項目名稱:OrthancAnonymization,代碼行數:11,代碼來源:JDBCConnector.java

示例13: setTotalPlaytime

import java.sql.Statement; //導入方法依賴的package包/類
public void setTotalPlaytime(String timePlayed, String titleID){
	try{
		Statement stmt = connection.createStatement(); 
		stmt.executeUpdate("UPDATE local_roms SET timePlayed='"+timePlayed+"' WHERE titleID = '"+titleID+"';");
		connection.commit();
		stmt.close();
	}catch(SQLException e){
		LOGGER.error("failed to set total play time", e);
		e.printStackTrace();
	}
}
 
開發者ID:Seil0,項目名稱:cemu_UI,代碼行數:12,代碼來源:DBController.java

示例14: testBug37570

import java.sql.Statement; //導入方法依賴的package包/類
public void testBug37570() throws Exception {
    Properties props = new Properties();
    props.setProperty("characterEncoding", "utf-8");
    props.setProperty("passwordCharacterEncoding", "utf-8");

    // TODO enable for usual connection?
    Connection adminConn = getAdminConnectionWithProps(props);

    if (adminConn != null) {

        String unicodePassword = "\u0430\u0431\u0432"; // Cyrillic string
        String user = "bug37570";
        Statement adminStmt = adminConn.createStatement();

        adminStmt.executeUpdate("create user '" + user + "'@'127.0.0.1' identified by 'foo'");
        adminStmt.executeUpdate("grant usage on *.* to '" + user + "'@'127.0.0.1'");
        adminStmt.executeUpdate("update mysql.user set password=PASSWORD('" + unicodePassword + "') where user = '" + user + "'");
        adminStmt.executeUpdate("flush privileges");

        try {
            ((MySQLConnection) adminConn).changeUser(user, unicodePassword);
        } catch (SQLException sqle) {
            assertTrue("Connection with non-latin1 password failed", false);
        }

    }
}
 
開發者ID:rafallis,項目名稱:BibliotecaPS,代碼行數:28,代碼來源:ConnectionRegressionTest.java

示例15: deleteAllGames

import java.sql.Statement; //導入方法依賴的package包/類
/**
*Method to delete all games
*
*@throws SQLException if no database connection is found or another error occurs
*/
@Override
public void deleteAllGames() throws SQLException{
  Connection connection = DB.openConnection();
  Statement s = connection.createStatement();
  s.executeUpdate(DELETE_ALL);
  s.close();
  connection.close();
}
 
開發者ID:StefanoMartella,項目名稱:GamingPlatform,代碼行數:14,代碼來源:GiocoDao.java


注:本文中的java.sql.Statement.executeUpdate方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。