久久机这里只有精品,国产69精品一区二区亚洲孕妇,91精品国产综合久久婷婷香蕉,午夜久久久久久电影

最新活動(dòng):電腦PC端+手機(jī)端+微網(wǎng)站+自適應(yīng)網(wǎng)頁多模板選擇-建站388元起價(jià)!!!
當(dāng)前位置:主頁 > 網(wǎng)站建設(shè) > 判斷數(shù)據(jù)庫表是否存在以及修改表名的方法建站

判斷數(shù)據(jù)庫表是否存在以及修改表名的方法建站

時(shí)間:2023-05-22 17:05:22 閱讀: 文章分類: 網(wǎng)站建設(shè) 作者: 建站小能手

導(dǎo)讀:1建站知識(shí)本文為大家詳細(xì)介紹下如何判斷數(shù)據(jù)庫表是否存在以及修改表名,感興趣的朋友可以參考下,希望對(duì)大家有所幫助網(wǎng)站seo優(yōu)化培訓(xùn)seo網(wǎng)站優(yōu)化培訓(xùn)。

網(wǎng)站seo優(yōu)化培訓(xùn)seo網(wǎng)站優(yōu)化培訓(xùn)一、判斷數(shù)據(jù)庫表是否存在: 首先要拿到數(shù)據(jù)庫連接conn,調(diào)用DatabaseMetaData dbmd = conn.getDataMeta();之后調(diào)用如下方法:

復(fù)制代碼 代碼如下:

/**網(wǎng)站seo優(yōu)化課程 * 根據(jù)表名,判斷數(shù)據(jù)庫表是否存在 * @param tableName * @return true:存在該表,false:不存在該表 */ public boolean hasTable(String tableName) { Init(); boolean result = false; //判斷某一個(gè)表是否存在 try{ ResultSet set = dbmd.getTables (null, null, tableName, null); //獲取查找結(jié)果 while (set.next()) { //如果查找結(jié)果不為空,則說明存在該表 result = true; //將返回結(jié)果置為true } }catch(Exception e){ e.printStackTrace(); } return result; }

二、修改表名: 首先依然要拿到數(shù)據(jù)庫連接conn和數(shù)據(jù)庫描述對(duì)象dbmd以及Statement對(duì)象st,之后調(diào)用如下方法

復(fù)制代碼 代碼如下:

/** * 修改表名 * @param srcTableName 源表名 * @param newTableName 新表名 * @return true:修改表名成功,false:修改表名失敗 */ public boolean renameTable(String srcTableName,String ne網(wǎng)站優(yōu)化seo培訓(xùn)wTableName){ Init(); boolean result = false; StringBuffer sql = new StringBuffer(); try{ String dataBaseType = dbmd.getDatabaseProductName(); //獲取數(shù)據(jù)庫類型 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()); //執(zhí)行更新操作,返回結(jié)果 if(1==temp){ result = true; //將返回值設(shè)為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()); //執(zhí)行更新操作,返回結(jié)果 if(0==temp){ result = true; //將返回值設(shè)為true } }catch(Exception e){ e.printStackTrace(); } }else{ //尚未實(shí)現(xiàn)對(duì)oracle和db2判斷 } }catch(Exception e){ e.printStackTrace(); } //System.out.println(rseo網(wǎng)站優(yōu)化esult); return result; }

相關(guān)網(wǎng)站seo優(yōu)化培訓(xùn)seo網(wǎng)站優(yōu)化培訓(xùn)。

關(guān)鍵詞標(biāo)簽: 標(biāo)簽 是否存在

聲明: 本文由我的SEOUC技術(shù)文章主頁發(fā)布于:2023-05-22 ,文章判斷數(shù)據(jù)庫表是否存在以及修改表名的方法建站主要講述是否存在,標(biāo)簽,判斷數(shù)據(jù)庫表是否存在以及修改表網(wǎng)站建設(shè)源碼以及服務(wù)器配置搭建相關(guān)技術(shù)文章。轉(zhuǎn)載請保留鏈接: http://www.bifwcx.com/article/web_4876.html

我的IDC 網(wǎng)站建設(shè)技術(shù)SEOUC.COM
專注網(wǎng)站建設(shè),SEO優(yōu)化,小程序設(shè)計(jì)制作搭建開發(fā)定制網(wǎng)站等,數(shù)千家網(wǎng)站定制開發(fā)案例,網(wǎng)站推廣技術(shù)服務(wù)。
  • 5000+合作客服
  • 8年從業(yè)經(jīng)驗(yàn)
  • 150+覆蓋行業(yè)
  • 最新熱門源碼技術(shù)文章

    主站蜘蛛池模板: 新安县| 保康县| 吴桥县| 弥渡县| 安庆市| 宜丰县| 梁山县| 九江市| 乌兰浩特市| 宁蒗| 沅江市| 靖安县| 铜川市| 微山县| 思南县| 沂水县| 黔西| 泰来县| 潼南县| 临沂市| 辽宁省| 红河县| 游戏| 正镶白旗| 珲春市| 揭西县| 镇赉县| 巴东县| 黑河市| 清丰县| 宜章县| 海口市| 剑川县| 西畴县| 广安市| 五莲县| 鞍山市| 杂多县| 蒙自县| 瑞金市| 大厂|