本文整理匯總了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);
}
}
示例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();
}
示例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();
}
}
}
}
示例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;
}
}
示例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;
}
}
示例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();
}
}
示例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);
}
}
示例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();
}
}
示例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();
}
}
示例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();
}
示例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());
}
示例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;
}
示例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();
}
}
示例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);
}
}
}
示例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();
}