本文整理匯總了Java中com.mysql.jdbc.Statement.executeUpdate方法的典型用法代碼示例。如果您正苦於以下問題:Java Statement.executeUpdate方法的具體用法?Java Statement.executeUpdate怎麽用?Java Statement.executeUpdate使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.mysql.jdbc.Statement
的用法示例。
在下文中一共展示了Statement.executeUpdate方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: excSql
import com.mysql.jdbc.Statement; //導入方法依賴的package包/類
/**
* 說明:用於執行插入、更新、刪除的sql語句,當受影響的行數為0和執行失敗時返回false
*
* @param sql
* @return boolean 成功返回true,失敗返回false
*/
public boolean excSql(String sql) {
if (con == null)
getConnection(); // 連接到數據庫
try {
Statement st = (Statement) con.createStatement(); // 創建用於執行靜態sql語句的Statement對象
int counts = st.executeUpdate(sql); // 執行操作的sql語句
if (0 == counts) {
log.info("執行成功,,共0條數據受到影響,沒有完成操作!:SQL語句-->【" + sql + "】");
return false;
}
log.info("執行成功,共" + counts + "條數據受到影響:" + "SQL語句-->【" + sql + "】");
return true;
} catch (SQLException e) {
log.error("執行失敗:SQL語句-->【" + sql + "】");
log.error(e.getMessage());
return false;
}
}
示例2: getSqlExecuteUpdate
import com.mysql.jdbc.Statement; //導入方法依賴的package包/類
/**
* This Method executes a SQL-Statement (Create, Insert, Update) in
* the database and returns true if this was successful
* @param sqlStatement the SQL-Statement to execute
* @return True, if the execution was successful
*/
public boolean getSqlExecuteUpdate(String sqlStatement) {
boolean successfull = false;
Statement state = null;
try {
state = getNewStatement();
state.executeUpdate(sqlStatement);
successfull = true;
} catch (SQLException e) {
//e.printStackTrace();
String msg = e.getLocalizedMessage() + newLine;
msg += sqlStatement;
this.dbError.setText(msg);
this.dbError.put2Clipboard(sqlStatement);
this.dbError.setErrNumber( e.getErrorCode() );
this.dbError.setHead( "Fehler bei der Ausführung von 'executeUpdate'!" );
this.dbError.setErr(true);
this.dbError.show();
} finally {
try {
if (state!=null) state.close();
} catch (SQLException sqle) {
sqle.printStackTrace();
}
}
return successfull;
}
示例3: eliminar
import com.mysql.jdbc.Statement; //導入方法依賴的package包/類
void eliminar(Integer id) {
try {
String Query = "DELETE FROM `registros` WHERE idUsuario=" + id;
Statement st = (Statement) conexion.createStatement();
st.executeUpdate(Query);
System.out.println("(LOG) [OK] DB Eliminando usuario " + id);
} catch (SQLException ex) {
Logger.getLogger(DB.class.getName()).log(Level.SEVERE, null, ex);
}
}
示例4: eliminar
import com.mysql.jdbc.Statement; //導入方法依賴的package包/類
public void eliminar(Integer id) {
try {
String Query = "DELETE FROM `registros` WHERE idUsuario=" + id;
Statement st = (Statement) conexion.createStatement();
st.executeUpdate(Query);
System.out.println("(LOG) [OK] DB Eliminando usuario " + id);
} catch (SQLException ex) {
Logger.getLogger(DB.class.getName()).log(Level.SEVERE, null, ex);
}
}
示例5: insert
import com.mysql.jdbc.Statement; //導入方法依賴的package包/類
/**
* @desc Method to insert data to a table
* @param insertQuery String The Insert query
* @return boolean
* @throws SQLException
*/
public int insert(String insertQuery) throws SQLException {
statement = (Statement) db.conn.createStatement();
int result = statement.executeUpdate(insertQuery);
return result;
}
示例6: InsertOrganization
import com.mysql.jdbc.Statement; //導入方法依賴的package包/類
/**
* Inserts organizations into DB.
*
* @param ministry - The ministry object
* @param url - The url of the ministry
* @throws java.sql.SQLException
*/
public static void InsertOrganization(Object ministry, String url, String minGroup) throws SQLException {
Statement stmt = connection.createStatement();
ResultSet rs = stmt.executeQuery("SELECT ID, GROUP_TITLE FROM ORGANIZATION_LKP WHERE title = '" + ministry + "';");
int id = -1;
if (rs.next()) {
id = rs.getInt(1);
String group_title = rs.getString(2);
if (group_title == null || !group_title.equals(minGroup)) {
stmt.executeUpdate("UPDATE ORGANIZATION_LKP SET group_title = '" + minGroup + "' WHERE id = " + id + ";");
}
} else {
stmt.execute("INSERT INTO ORGANIZATION_LKP (title, url_initial) VALUES ('" + ministry + "','" + url + "');");
}
}
示例7: executeUpdate
import com.mysql.jdbc.Statement; //導入方法依賴的package包/類
public int executeUpdate(String query) throws SQLException {
int ret = 0;
Statement stmt = conn.createStatement();
stmt.setEscapeProcessing(true);
stmt.executeUpdate(query);
ResultSet tmp = stmt.getGeneratedKeys();
if (tmp.next()) {
// Retrieve the auto generated key(s).
ret = tmp.getInt(1);
}
stmt.close();
return ret;
}
示例8: createTable
import com.mysql.jdbc.Statement; //導入方法依賴的package包/類
private static synchronized void createTable() throws TalesException{
try {
String sql = "CREATE TABLE `logs` ("
+ "`id` int(11) NOT NULL AUTO_INCREMENT,"
+ "`publicDNS` varchar(100) COLLATE utf8_unicode_ci NOT NULL,"
+ "`pid` int(7) COLLATE utf8_unicode_ci NOT NULL,"
+ "`logType` varchar(100) COLLATE utf8_unicode_ci NOT NULL,"
+ "`methodPath` varchar(500) COLLATE utf8_unicode_ci NOT NULL,"
+ "`lineNumber` int(11) NOT NULL,"
+ "`data` varchar(5000) COLLATE utf8_unicode_ci NOT NULL,"
+ "`added` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,"
+ "PRIMARY KEY (`id`),"
+ "KEY `publicDNS` (`publicDNS`),"
+ "KEY `pid` (`pid`),"
+ "KEY `logType` (`logType`),"
+ "KEY `methodPath` (`methodPath`(333))"
+ ") ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1 ;";
Statement statement = (Statement) conn.createStatement();
statement.executeUpdate(sql);
statement.close();
}catch(Exception e){
throw new TalesException(new Throwable(), e);
}
}
示例9: createDatabase
import com.mysql.jdbc.Statement; //導入方法依賴的package包/類
private static void createDatabase(String dbName) throws TalesException{
try {
final String sql = "CREATE DATABASE " + Globals.DATABASE_NAMESPACE + dbName;
final Statement statement = (Statement) conn.createStatement();
statement.executeUpdate(sql);
statement.close();
}catch(final Exception e){
final String[] args = {dbName};
throw new TalesException(new Throwable(), e, args);
}
}
示例10: createTable
import com.mysql.jdbc.Statement; //導入方法依賴的package包/類
private synchronized void createTable() throws TalesException{
try {
Statement statement = (Statement) conn.createStatement();
statement.executeUpdate("CREATE TABLE " + taskName + " (id INT NOT NULL, name VARCHAR( 500 ) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL) ENGINE = MYISAM CHARSET=utf8");
// clone
statement.close();
}catch(Exception e){
String[] args = {taskName};
throw new TalesException(new Throwable(), e, args);
}
}
示例11: createStringAttributeTable
import com.mysql.jdbc.Statement; //導入方法依賴的package包/類
private synchronized final void createStringAttributeTable(final String attributeName) throws TalesException{
try {
String tbName = Globals.ATTRIBUTE_TABLE_NAMESPACE + attributeName;
tbName = tbName.replace(".", "_");
final Statement statement = (Statement) conn.createStatement();
statement.executeUpdate("CREATE TABLE " + tbName + " (id INT NOT NULL AUTO_INCREMENT, documentId INT NOT NULL, data VARCHAR(2000) CHARACTER SET utf8 COLLATE utf8_unicode_ci NULL, added TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (id), KEY documentId (documentId)) ENGINE = MYISAM DEFAULT CHARSET=utf8");
statement.executeUpdate("OPTIMIZE TABLE " + tbName);
statement.close();
}catch(final Exception e){
final String[] args = {attributeName};
throw new TalesException(new Throwable(), e, args);
}
}
示例12: createIgnoredDocumentsTable
import com.mysql.jdbc.Statement; //導入方法依賴的package包/類
private final synchronized void createIgnoredDocumentsTable() throws TalesException{
try {
final String sql = "CREATE TABLE ignoredDocuments ("
+ "id INT NOT NULL AUTO_INCREMENT, "
+ "name VARCHAR(1000) NOT NULL, "
+ "added timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, "
+ "PRIMARY KEY (id)"
+ ") ENGINE = MYISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1;";
final Statement statement = (Statement) conn.createStatement();
statement.executeUpdate(sql);
statement.close();
}catch(final Exception e){
throw new TalesException(new Throwable(), e);
}
}
示例13: deleteTaskTablesFromDomain
import com.mysql.jdbc.Statement; //導入方法依賴的package包/類
public static void deleteTaskTablesFromDomain(String domain) throws TalesException {
try {
// connects
Class.forName("com.mysql.jdbc.Driver");
Connection conn = DriverManager.getConnection("jdbc:mysql://"+
Config.getTasksDBHost(domain)+":"+Config.getDBPort(domain)+"/"+
"tales_tasks" +
"?user=" + Config.getDBUsername() +
"&password=" + Config.getDBPassword() +
"&useUnicode=true&characterEncoding=UTF-8"
);
// gets all the tables that contains the domain name
Statement statement = (Statement) conn.createStatement();
ResultSet rs = statement.executeQuery("SHOW TABLES LIKE '%" + domain + "'");
while(rs.next()){
Logger.log(new Throwable(), "dropping task table \"" + rs.getString(1) + "\"");
Statement statement2 = (Statement) conn.createStatement();
statement2.executeUpdate("DROP TABLE " + rs.getString(1));
statement2.close();
}
rs.close();
statement.close();
conn.close();
}catch(Exception e){
throw new TalesException(new Throwable(), e);
}
}
示例14: createDocumentsTable
import com.mysql.jdbc.Statement; //導入方法依賴的package包/類
private final synchronized void createDocumentsTable() throws TalesException{
try {
final String sql = "CREATE TABLE documents (id int(11) NOT NULL AUTO_INCREMENT,"
+ "name varchar(1000) NOT NULL,"
+ "added timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,"
+ "lastUpdate timestamp NOT NULL DEFAULT '1999-12-31 17:00:00',"
+ "active int(2) NOT NULL DEFAULT '1',"
+ "PRIMARY KEY (id),"
+ "KEY lastUpdate (lastUpdate),"
+ "KEY active (active)"
+ ") ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1;";
final Statement statement = (Statement) conn.createStatement();
statement.executeUpdate(sql);
statement.close();
}catch(final Exception e){
throw new TalesException(new Throwable(), e);
}
}
示例15: deleteAll
import com.mysql.jdbc.Statement; //導入方法依賴的package包/類
public final void deleteAll() throws TalesException {
try {
// db
Logger.log(new Throwable(), "dropping database");
final Statement statement = (Statement) conn.createStatement();
statement.executeUpdate("drop database " + Globals.DATABASE_NAMESPACE + dbName);
statement.close();
// redis
final Jedis redis = jedisPool.getResource();
final Set<String> keys = redis.keys(dbName + "*");
Logger.log(new Throwable(), "deleting " + keys.size() + " redis keys");
for(final String key : keys){
redis.del(key);
}
jedisPool.returnResource(redis);
}catch(final Exception e){
throw new TalesException(new Throwable(), e);
}
}