本文整理汇总了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);
}
}