Java中的元數據,定義為關於數據的數據,稱為「元數據」。元資料也被認為是有關使用者所需資訊的文檔。這是資料倉儲的重要面向之一。
廣告 該類別中的熱門課程 JAVA 掌握 - 專業化 | 78 課程系列 | 15 次模擬測驗即時範例:圖書館目錄、目錄、有關人員資料的資料項目(人員體重、人員行走等)等
元資料由下列內容組成:
- 系統及其組件的描述和位置。
- 它還有資料和最終使用者視圖的名稱、定義、內容和結構。
- 權威資料辨識。
- 積分和轉換規則用於填充資料。
- 訂閱者的訂閱資訊。
- 用於分析資料使用情況和效能。
為什麼需要元資料?
它為 Java 開發人員提供有關表資料、庫目錄等內容和結構的資訊。
元資料型別
有 3 種類型的元資料:
- 操作元資料
- 擷取與轉換元資料
- 最終用戶元資料
1。操作元資料:操作元資料擁有操作資料來源的所有資訊。資料倉儲在從來源系統中選擇資訊時,會對記錄進行劃分,結合不同來源的文件因素,並處理多種編碼方案和欄位長度。當我們將資訊傳遞給最終用戶時,我們必須能夠返回來源資料集。
2。提取和轉換元資料:提取和轉換元資料包括有關從來源系統中刪除資料的資料。資料提取的提取方法、頻率和業務規則屬於提取和轉換元資料。
3。最終用戶元資料:最終用戶元資料是資料室的導航圖。它使最終用戶能夠從資料倉儲中找到資料。
元資料在 Java 中如何運作?
Java 元資料是基於提供給它的資料工作。它提供了有關數據的數據資訊。
文法:
class Metadata{ public static void main(String args[]){ try{ //load required database class //creating database metadata class DatabaseMetaData metaData=con.getMetaData(); //display the metadata of the table content System.out.println(metaData.getDriverName()); System.out.println(metaData.getDriverVersion()); System.out.println(metaData.getUserName()); System.out.println(metaData.getDatabaseProductName()); System.out.println(metaData.getDatabaseProductVersion()); con.close(); }catch(Exception e){ System.out.println(e);} } }注意: 在進入範例之前,您必須需要 MySQL 資料庫和 mysql-connector jar。
用 Java 實作元資料的範例
以下是 Java 中元資料的範例:
範例 #1 – 結果集元資料
代碼:
import java.sql.*;//importing sql package public class A {//Creating class //main method for run the application public static void main(String args[]) { try { //loading my sql driver Class.forName("com.mysql.jdbc.Driver"); //get the connection by providing database, user name and password Connection connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/test", "root", "root"); //select the all from employee table PreparedStatement preparedStatement = connection.prepareStatement("select * from employee"); //executing the query ResultSet resultSet = preparedStatement.executeQuery(); //Create result meta data for get the meta data of table ResultSetMetaData resultSetMetaData = resultSet.getMetaData(); //Displaying meta data of employee table System.out.println("Total Number of columns: " + resultSetMetaData.getColumnCount()); System.out.println("1st Column name : " + resultSetMetaData.getColumnName(1)); System.out.println("2nd Column name : " + resultSetMetaData.getColumnName(2)); System.out.println("3rd Column name : " + resultSetMetaData.getColumnName(3)); System.out.println("Column Type Name of 1st column: " + resultSetMetaData.getColumnTypeName(1)); System.out.println("Column Type Name of 2nd column: " + resultSetMetaData.getColumnTypeName(2)); System.out.println("Column Type Name of 3rd column: " + resultSetMetaData.getColumnTypeName(3)); connection.close(); } catch (Exception e) { System.out.println(e); } } }
輸出:
範例 #2 – 資料庫元資料
代碼:
import java.sql.*;//importing sql package public class A {//Creating class //main method for run the application public static void main(String args[]) { try { //loading my sql driver Class.forName("com.mysql.jdbc.Driver"); //get the connection by providing database, user name and password Connection connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/test","root", "root"); //select the all from employee table PreparedStatement preparedStatement = connection.prepareStatement("select * from employee"); //executing the query preparedStatement.executeQuery(); //Create databse result set meta data for get the meta data of databse of mysql DatabaseMetaData databaseMetaData=connection.getMetaData(); //Displaying meta data of mysql table System.out.println("MYSQL Driver Name: "+databaseMetaData.getDriverName()); System.out.println("MYSQL Driver Version: "+databaseMetaData.getDriverVersion()); System.out.println("MYSQL UserName: "+databaseMetaData.getUserName()); System.out.println("MYSQL Database Product Name:"+databaseMetaData.getDatabaseProductName()); System.out.println("MYSQL Database Product Version: "+databaseMetaData.getDatabaseProductVersion()); connection.close(); } catch (Exception e) { System.out.println(e); } } }
輸出:
範例 #3 – 用於擷取表格名稱的資料庫元資料
代碼:
import java.sql.*;//importing sql package public class A {// Creating class // main method for run the application public static void main(String args[]) { try { // loading my sql driver Class.forName("com.mysql.jdbc.Driver"); // get the connection by providing database, user name and password Connection connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/test", "root", "root"); // Create databse result set meta data for get the meta data of // databse of mysql DatabaseMetaData dbmd = connection.getMetaData(); String table[] = { "VIEW" }; ResultSet resultSet = dbmd.getTables(null, null, null, table); // iterating number table names from database of mysql while (resultSet.next()) { System.out.println("Table name is: "+resultSet.getString(3)); } connection.close(); } catch (Exception e) { System.out.println(e); } } }
輸出:
結論
Java中的元資料用於了解資料的資料。例如,表格欄位名稱、欄位資料類型、欄位資料類型長度、資料庫表格名稱、特定資料庫中存在的資料庫數量等
以上是Java 中的元數據的詳細內容。更多資訊請關注PHP中文網其他相關文章!

熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

AI Hentai Generator
免費產生 AI 無盡。

熱門文章

熱工具

WebStorm Mac版
好用的JavaScript開發工具

記事本++7.3.1
好用且免費的程式碼編輯器

Atom編輯器mac版下載
最受歡迎的的開源編輯器

SecLists
SecLists是最終安全測試人員的伙伴。它是一個包含各種類型清單的集合,這些清單在安全評估過程中經常使用,而且都在一個地方。 SecLists透過方便地提供安全測試人員可能需要的所有列表,幫助提高安全測試的效率和生產力。清單類型包括使用者名稱、密碼、URL、模糊測試有效載荷、敏感資料模式、Web shell等等。測試人員只需將此儲存庫拉到新的測試機上,他就可以存取所需的每種類型的清單。

SAP NetWeaver Server Adapter for Eclipse
將Eclipse與SAP NetWeaver應用伺服器整合。