sdelete.java
来自「主要对各种数据库性能进行测试」· Java 代码 · 共 100 行
JAVA
100 行
package sqlite;
import java.sql.PreparedStatement;
import java.sql.SQLException;
public class SDelete extends ServerFactory {
static int ist;
static long max=0;
static long min=0;
static long total;
long avg=0;
ExecSql exec = new ExecSql();
String table = "USERS";
WriteFile file = new WriteFile();
Configure config = new Configure();
String dbtype = "";
int newval = 0;
static int thenum = 0;
public SDelete() {
String dbtype = config.getProperty("dbtype");
this.dbtype = dbtype;
exec = new ExecSql();
this.init();
}
@Override
public int Exec() {
thenum ++;
newval = thenum;
this.delete();
return 0;
}
synchronized void delete() {
try {
String sql="";
conn.setAutoCommit(false);
sql = "drop table " + table;
PreparedStatement st = conn.prepareStatement(sql);
try{
st.executeUpdate();
}catch(SQLException se){
System.out.println("表"+table+"不存在!");
}
if(st!=null) {
st.close();
st = null;
}
conn.commit();
System.out.println( "删除数据成功!");
file.aLine("删除数据成功!");
} catch (SQLException e) {
// TODO Auto-generated catch block
//System.out.println(e.getMessage());
e.printStackTrace();
try{
if(conn!=null) {
exec.closeConn(conn);
System.out.println("disconnect");
file.aLine("disconnect");
}
}catch(Exception ee){
ee.printStackTrace();
}
}catch (Exception e) {
// TODO Auto-generated catch block
//System.out.println(e.getMessage());
e.printStackTrace();
}
finally{
freeConnection(this.dbtype);
if(conn!=null)
exec.closeConn(conn);
}
}
@Override
public int init() {
// TODO Auto-generated method stub
this.dbtype = config.getProperty("dbtype");
if(!initConnection(this.dbtype))
{
System.out.println("create database connection failed!");
return -1;
}
return 0;
}
public static void main(String[] args)
{
SDelete as = new SDelete();
as.Exec();
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?