鑾峰彇鏁版嵁搴撶殑鎵€鏈夎〃锛氾紙浠ySQL鍜孫racle涓轰緥锛屽叾浠栫被鍨嬬殑鏁版嵁搴撴帴瑙︿笉杩囷紝涓嶅仛瑙i噴锛?/p>
Connection鎺ュ彛涓彁渚涗簡DatabaseMetaData鎺ュ彛锛?/p>
鎻愪緵锛歡etTables()鏂规硶锛岃鏂规硶闇€瑕佷紶杩?涓弬鏁帮細
绗竴涓槸鏁版嵁搴撳悕绉帮紝瀵逛簬MySQL锛屽垯瀵瑰簲鐩稿簲鐨勬暟鎹簱锛屽浜嶰racle鏉ヨ锛屽垯鏄搴旂浉搴旂殑鏁版嵁搴撳疄渚嬶紝鍙互涓嶅~锛屼篃鍙互鐩存帴浣跨敤Connection鐨勫疄渚嬪璞′腑鐨刧etCatalog()鏂规硶杩斿洖鐨勫€煎~鍏咃紱
绗簩涓槸妯″紡锛屽彲浠ョ悊瑙d负鏁版嵁搴撶殑鐧诲綍鍚嶏紝鑰屽浜嶰racle涔熷彲浠ョ悊瑙f垚瀵硅鏁版嵁搴撴搷浣滅殑鎵€鏈夎€呯殑鐧诲綍鍚嶃€傚浜嶰racle瑕佺壒鍒敞鎰忥紝鍏剁櫥闄嗗悕蹇呴』鏄ぇ鍐欙紝涓嶇劧鐨勮瘽鏄棤娉曡幏鍙栧埌鐩稿簲鐨勬暟鎹紝鑰孧ySQL鍒欎笉鍋氬己鍒惰姹傘€?/p>
绗笁涓槸琛ㄥ悕绉帮紝涓€鑸儏鍐典笅濡傛灉瑕佽幏鍙栨墍鏈夌殑琛ㄧ殑璇濓紝鍙互鐩存帴璁剧疆涓簄ull锛屽鏋滆缃负鐗瑰畾鐨勮〃鍚嶇О锛屽垯杩斿洖璇ヨ〃鐨勫叿浣撲俊鎭€?/p>
绗洓涓槸绫诲瀷鏍囧噯,浠ユ暟缁勫舰寮忎紶鍊硷紝鏈?TABLE"銆?VIEW"銆?SYSTEM TABLE"銆?GLOBAL TEMPORARY"銆?LOCAL TEMPORARY"銆?ALIAS" 鍜?"SYNONYM"杩欏嚑涓粡鍏哥殑绫诲瀷锛屼竴鑸娇鐢ㄢ€漈ABLE鈥濓紝鍗宠幏鍙栨墍鏈夌被鍨嬩负TABLE鐨勮〃
瀹冭繑鍥炰竴涓猂esultSet瀵硅薄锛屾湁10鍒楋紝璇︾粏鐨勬樉绀轰簡琛ㄧ殑绫诲瀷锛?/p>
TABLE_CAT String => 琛ㄧ被鍒紙鍙负 null锛?/p>
TABLE_SCHEM String => 琛ㄦā寮忥紙鍙负 null锛?/p>
TABLE_NAME String => 琛ㄥ悕绉?/p>
TABLE_TYPE String => 琛ㄧ被鍨嬨€?/p>
REMARKS String => 琛ㄧ殑瑙i噴鎬ф敞閲?/p>
TYPE_CAT String => 绫诲瀷鐨勭被鍒紙鍙负 null锛?/p>
TYPE_SCHEM String => 绫诲瀷妯″紡锛堝彲涓?null锛?/p>
TYPE_NAME String => 绫诲瀷鍚嶇О锛堝彲涓?null锛?/p>
SELF_REFERENCING_COL_NAME String => 鏈夌被鍨嬭〃鐨勬寚瀹?"identifier" 鍒楃殑鍚嶇О锛堝彲涓?null锛?/p>
REF_GENERATION String
鍙牴鎹渶瑕佷娇鐢?/p>
绀轰緥:
锛圡ySQL锛?/p>
DatabaseMetaData metaData = conn.getMetaData();
ResultSet rs = metaData.getTables(conn.getCatalog(), "root", null, new String[]{"TABLE"});
while(rs.next()) {
聽聽 System.out.println(rs.getString("TABLE_NAME"));
}
锛圤racle锛?/p>
DatabaseMetaData metaData = conn.getMetaData();
ResultSet rs = metaData.getTables(conn.getCatalog(), "SCOTT", null, new String[]{"TABLE"});
while(rs.next()) {
聽聽聽聽System.out.println(rs.getString("TABLE_NAME"));
}
杩欎袱澶勭殑浠g爜锛屽敮涓€鍖哄埆鐨勬槸鍦ㄧ浜屼釜鍙傛暟锛孫racle涓嶆敮鎸佸皬鍐欑殑锛屽繀椤绘槸澶у啓鐨勶紝鎹㈡垚灏忓啓鍒欎粈涔堥兘鑾峰彇涓嶅埌锛岃€孧ySQL鍒欏ぇ灏忓啓淇卞彲锛屼笉杩囨垜寤鸿鏄叏閮ㄤ娇鐢ㄥぇ鍐欙紝杩欓噷鍙槸绀轰緥路路路路路路