本文整理汇总了Java中java.sql.PreparedStatement.executeUpdate方法的典型用法代码示例。如果您正苦于以下问题:Java PreparedStatement.executeUpdate方法的具体用法?Java PreparedStatement.executeUpdate怎么用?Java PreparedStatement.executeUpdate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.sql.PreparedStatement
的用法示例。
在下文中一共展示了PreparedStatement.executeUpdate方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: addMember
import java.sql.PreparedStatement; //导入方法依赖的package包/类
public void addMember(Organization organization, User user) {
PreparedStatement preparedStatement = null;
final String query = "INSERT INTO Members(user, organization) VALUES (?,?)";
try {
preparedStatement = initializePreparedStatement(query, false, user.getId(), organization.getId());
int status = preparedStatement.executeUpdate();
if (status == 0) {
throw new DAOException("Impossible d'ajouter ce membre");
} else {
organization.addMember(user);
}
} catch (SQLException e) {
throw new DAOException(e);
} finally {
close(preparedStatement);
}
}
示例2: setMessageShared
import java.sql.PreparedStatement; //导入方法依赖的package包/类
@Override
public void setMessageShared(Connection txn, MessageId m) throws DbException {
PreparedStatement ps = null;
try {
String sql = "UPDATE messages SET shared = TRUE"
+ " WHERE messageId = ?";
ps = txn.prepareStatement(sql);
ps.setBytes(1, m.getBytes());
int affected = ps.executeUpdate();
if (affected < 0 || affected > 1) throw new DbStateException();
ps.close();
} catch (SQLException e) {
tryToClose(ps);
throw new DbException(e);
}
}
示例3: execute
import java.sql.PreparedStatement; //导入方法依赖的package包/类
public void execute() {
PreparedStatement prest;
try {
prest = connection.prepareStatement(sql);
int i = 1;
for (Object object : values) {
prest.setObject(i, object);
i++;
}
prest.executeUpdate();
prest.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
示例4: setContactActive
import java.sql.PreparedStatement; //导入方法依赖的package包/类
@Override
public void setContactActive(Connection txn, ContactId c, boolean active)
throws DbException {
PreparedStatement ps = null;
try {
String sql = "UPDATE contacts SET active = ? WHERE contactId = ?";
ps = txn.prepareStatement(sql);
ps.setBoolean(1, active);
ps.setInt(2, c.getInt());
int affected = ps.executeUpdate();
if (affected < 0 || affected > 1) throw new DbStateException();
ps.close();
} catch (SQLException e) {
tryToClose(ps);
throw new DbException(e);
}
}
示例5: insertIdRows
import java.sql.PreparedStatement; //导入方法依赖的package包/类
/**
* Insert rows with id = [low, hi) into tableName.
*/
private void insertIdRows(String tableName, int low, int hi)
throws SQLException {
SqoopOptions options = new SqoopOptions();
options.setConnectString(SOURCE_DB_URL);
HsqldbManager manager = new HsqldbManager(options);
Connection c = manager.getConnection();
PreparedStatement s = null;
try {
s = c.prepareStatement("INSERT INTO " + manager.escapeTableName(tableName) + " VALUES(?)");
for (int i = low; i < hi; i++) {
s.setInt(1, i);
s.executeUpdate();
}
c.commit();
} finally {
if(s != null) {
s.close();
}
}
}
示例6: addPandoraItem
import java.sql.PreparedStatement; //导入方法依赖的package包/类
public void addPandoraItem(int inv) {
MapleInventoryType type = MapleInventoryType.getByType((byte) inv);
Item pan = c.getPlayer().getInventory(type).getItem((byte) 0);
if (type == null || pan == null) {
return;
}
try {
Connection con = DatabaseConnection.getConnection();
PreparedStatement ps = con.prepareStatement("INSERT INTO pandoraitems(itemid) VALUES (?)");
ps.setInt(1, pan.getItemId());
ps.executeUpdate();
ps.close();
} catch (SQLException e) {
System.out.print("Error excuting MySQL.");
return;
}
MapleInventoryManipulator.removeFromSlot(c, type, (byte) 0, pan.getQuantity(), false);
}
示例7: update
import java.sql.PreparedStatement; //导入方法依赖的package包/类
public int update(Object... args) throws SQLException {
Connection conn = null;
PreparedStatement st = null;
try {
conn = fac.getConnection();
st = conn.prepareStatement(sqlTemplate);
if (null != args && args.length > 0) {
int index = 1;
for (Object arg : args) {
setPrepareStatementParam(st, index, arg);
index++;
}
}
return st.executeUpdate();
}
catch (SQLException e) {
throw e;
}
finally {
bulidDAOThreadContext(conn, st);
}
}
示例8: setMessageState
import java.sql.PreparedStatement; //导入方法依赖的package包/类
@Override
public void setMessageState(Connection txn, MessageId m, State state)
throws DbException {
PreparedStatement ps = null;
try {
String sql = "UPDATE messages SET state = ? WHERE messageId = ?";
ps = txn.prepareStatement(sql);
ps.setInt(1, state.getValue());
ps.setBytes(2, m.getBytes());
int affected = ps.executeUpdate();
if (affected < 0 || affected > 1) throw new DbStateException();
ps.close();
} catch (SQLException e) {
tryToClose(ps);
throw new DbException(e);
}
}
示例9: alterar
import java.sql.PreparedStatement; //导入方法依赖的package包/类
/**
*@author Warley Rodrigues
*Criação e inserção de Pais, Estado, Cidade, Usuario e Postagem no banco de dados
*/
@Override
public void alterar(Estado p) throws SQLException, Exception {
Connection conexao = getConexao();
PreparedStatement pstmt;
pstmt = conexao.prepareStatement("update estados set nome = ?, pais = ? where id = ?");
pstmt.setString(1, p.getNome());
pstmt.setInt(2, p.getPais().getId());
pstmt.setInt(3, p.getId());
// executa uma inserção
pstmt.executeUpdate();
}
示例10: dropTableIfExists
import java.sql.PreparedStatement; //导入方法依赖的package包/类
/**
* Drop a table if it already exists in the database.
* @param table
* the name of the table to drop.
* @throws SQLException
* if something goes wrong.
*/
protected void dropTableIfExists(String table) throws SQLException {
Connection conn = getManager().getConnection();
String sqlStmt = "IF OBJECT_ID('" + table
+ "') IS NOT NULL DROP TABLE " + table;
PreparedStatement statement = conn.prepareStatement(sqlStmt,
ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
try {
statement.executeUpdate();
conn.commit();
} finally {
statement.close();
}
}
示例11: createMultiKeyTable
import java.sql.PreparedStatement; //导入方法依赖的package包/类
/**
* <p>Creates a table with three columns - A INT, B INT and C VARCHAR(32).
* This table is populated with records in a set of three with total records
* with the total number of unique values of A equal to the specified aMax
* value. For each value of A, there will be three records with value of
* B ranging from 0-2, and a corresponding value of C.</p>
* <p>For example if <tt>aMax = 2</tt>, the table will contain the
* following records:
* <pre>
* A | B | C
* ----------------------
* 0 | 0 | 0foo0
* 0 | 1 | 0foo1
* 0 | 2 | 0foo2
* 1 | 0 | 1foo0
* 1 | 1 | 1foo1
* 1 | 2 | 1foo2
* </pre></p>
* @param aMax the number of
* @throws SQLException
*/
private void createMultiKeyTable(int aMax) throws SQLException {
Connection conn = getConnection();
PreparedStatement statement = conn.prepareStatement(
"CREATE TABLE " + getTableName()
+ " (A INT NOT NULL, B INT NOT NULL, C VARCHAR(32))");
try {
statement.executeUpdate();
conn.commit();
} finally {
statement.close();
statement = null;
}
try {
for (int i = 0; i< aMax; i++) {
for (int j = 0; j < 3; j++) {
statement = conn.prepareStatement("INSERT INTO " + getTableName()
+ " VALUES (" + i + ", " + j + ", '"
+ i + "foo" + j + "')");
statement.executeUpdate();
statement.close();
statement = null;
}
}
} finally {
if (null != statement) {
statement.close();
}
}
conn.commit();
}
示例12: SetupSQL
import java.sql.PreparedStatement; //导入方法依赖的package包/类
public SetupSQL() {
try {
String hostname = Core.getInstance().sqlConfig.get().getString("sql.hostname");
String portnumber = Core.getInstance().sqlConfig.get().getString("sql.port");
String database = Core.getInstance().sqlConfig.get().getString("sql.database");
String username = Core.getInstance().sqlConfig.get().getString("sql.username");
String password = Core.getInstance().sqlConfig.get().getString("sql.password");
sqla = new SQLConnection(hostname, portnumber, database, username, password);
co = sqla.getConnection();
PreparedStatement sql = co
.prepareStatement(
"CREATE TABLE IF NOT EXISTS cache(uuid VARCHAR(255) NOT NULL PRIMARY KEY, name VARCHAR(100), totaltime INT default 0, firstjoined VARCHAR(100))");
table = new Table(co, "cache");
sql.executeUpdate();
Core.getInstance().getLogger().info("Succesfull connected to MYSQL");
valid = true;
} catch (Exception e) {
Core.getInstance().getLogger().info("-------- !WARNING! --------");
Core.getInstance().getLogger().info("Can't connect to your SQL server. Make sure SQL.yml is correct.... Shutting down..");
Core.getInstance().getLogger().warning("PROBLEM: "+e.getMessage());
Core.getInstance().getLogger().info("-------- !WARNING! --------");
Core.getInstance().getPluginLoader().disablePlugin(Core.getInstance());
valid = false;
return;
}
}
示例13: remove
import java.sql.PreparedStatement; //导入方法依赖的package包/类
@Override
public void remove(Suggestion s) {
try {
Connection connection = database.getConnection();
PreparedStatement stmt = connection.prepareStatement("DELETE FROM Suggestion WHERE id = ?");
stmt.setInt(1, s.getId());
stmt.executeUpdate();
stmt.close();
connection.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
示例14: testCsc4194InsertCheckText
import java.sql.PreparedStatement; //导入方法依赖的package包/类
private void testCsc4194InsertCheckText(Connection c, String tableName, String encoding) throws Exception {
byte[] kabuInShiftJIS = { (byte) 0x87, // a double-byte charater("kabu") in Shift JIS
(byte) 0x8a, };
String expected = new String(kabuInShiftJIS, encoding);
PreparedStatement testStmt = c.prepareStatement("INSERT INTO " + tableName + " VALUES (?)");
testStmt.setString(1, expected);
testStmt.executeUpdate();
this.rs = c.createStatement().executeQuery("SELECT field1 FROM " + tableName);
assertTrue(this.rs.next());
assertEquals(expected, this.rs.getString(1));
this.rs.close();
}
示例15: update
import java.sql.PreparedStatement; //导入方法依赖的package包/类
@Override
public void update(Rota rota) throws Exception {
PreparedStatement pstm = this.getConnectionFactory().getConnection()
.prepareStatement(RotaQueries.UPDATE_ROTA.getConsulta());
pstm.setInt(1, rota.getId());
pstm.setString(2, rota.getNome());
pstm.setObject(3, (rota.getOrigem() == null) ? null : rota.getOrigem().getId());
pstm.setObject(4, (rota.getDestino() == null) ? null : rota.getDestino().getId());
pstm.setDouble(7, rota.getCustoGrama());
pstm.setInt(8, rota.getTempoEntrega());
pstm.setInt(10, rota.getId());
if (rota instanceof Direta) {
Direta direta = (Direta) rota;
pstm.setDouble(5, direta.getCapacidadeTotal());
pstm.setDouble(6, direta.getCapacidadeAlocada());
pstm.setString(9, "D");
} else if (rota instanceof Fracional) {
pstm.setObject(5, null);
pstm.setObject(6, null);
pstm.setString(9, "F");
}
try {
pstm.executeUpdate();
if (rota instanceof Fracional)
this.updateTrechos((Fracional) rota);
} catch (Exception ex) {
throw new LogisticException("Erro durante a rotina de atualização de rotas.");
}
}