饿虎岗资源网 Design By www.oxmxm.com
一、判断数据库表是否存在:
首先要拿到数据库连接conn,调用DatabaseMetaData dbmd = conn.getDataMeta();之后调用如下方法:
复制代码 代码如下:
/**
* 根据表名,判断数据库表是否存在
* @param tableName
* @return true:存在该表,false:不存在该表
*/
public boolean hasTable(String tableName) {
Init();
boolean result = false; //判断某一个表是否存在
try{
ResultSet set = dbmd.getTables (null, null, tableName, null); //获取查找结果
while (set.next()) { //如果查找结果不为空,则说明存在该表
result = true; //将返回结果置为true
}
}catch(Exception e){
e.printStackTrace();
}
return result;
}

二、修改表名:
首先依然要拿到数据库连接conn和数据库描述对象dbmd以及Statement对象st,之后调用如下方法
复制代码 代码如下:
/**
* 修改表名
* @param srcTableName 源表名
* @param newTableName 新表名
* @return true:修改表名成功,false:修改表名失败
*/
public boolean renameTable(String srcTableName,String newTableName){
Init();
boolean result = false;
StringBuffer sql = new StringBuffer();
try{
String dataBaseType = dbmd.getDatabaseProductName(); //获取数据库类型
if(("Microsoft SQL Server").equals(dataBaseType)){ //sqlServer
try{
sql.append("EXEC sp_rename"+" "+srcTableName).append(",").append(newTableName);
int temp = 0;
temp = st.executeUpdate(sql.toString()); //执行更新操作,返回结果
if(1==temp){
result = true; //将返回值设为true
}
}catch(Exception e){
e.printStackTrace();
}
}else if(("HSQL Database Engine").equals(dataBaseType)||("MySQL").equals(dataBaseType)){ //hsql和mysql
try{
sql.append("ALTER TABLE"+" "+srcTableName+" "+"RENAME TO"+" "+newTableName);
int temp = 1;
temp = st.executeUpdate(sql.toString()); //执行更新操作,返回结果
if(0==temp){
result = true; //将返回值设为true
}
}catch(Exception e){
e.printStackTrace();
}
}else{ //尚未实现对oracle和db2判断
}
}catch(Exception e){
e.printStackTrace();
}
//System.out.println(result);
return result;
}
饿虎岗资源网 Design By www.oxmxm.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
饿虎岗资源网 Design By www.oxmxm.com

P70系列延期,华为新旗舰将在下月发布

3月20日消息,近期博主@数码闲聊站 透露,原定三月份发布的华为新旗舰P70系列延期发布,预计4月份上市。

而博主@定焦数码 爆料,华为的P70系列在定位上已经超过了Mate60,成为了重要的旗舰系列之一。它肩负着重返影像领域顶尖的使命。那么这次P70会带来哪些令人惊艳的创新呢?

根据目前爆料的消息来看,华为P70系列将推出三个版本,其中P70和P70 Pro采用了三角形的摄像头模组设计,而P70 Art则采用了与上一代P60 Art相似的不规则形状设计。这样的外观是否好看见仁见智,但辨识度绝对拉满。