首頁 > Java > java教程 > 主體

Java資料集

WBOY
發布: 2024-08-30 16:16:37
原創
401 人瀏覽過

java 中的資料集主要用於為 SQL 查詢中出現的資料提供安全視圖。它是名為 java.util.list 的庫的一部分,該庫保存大多數參數化的資料類型。當選擇方法的選擇註釋時,在這種情況下,查詢參數將用於具有其他存取修飾符(例如 public)的任何資料類,以實現從查詢到類別中存在的方法的可存取性。 java 中的資料集可以以連接或斷開的方式運作。

廣告 該類別中的熱門課程 JAVA 掌握 - 專業化 | 78 課程系列 | 15 次模擬測驗

什麼是 Java 資料集?

  • Dataset java 是一種公用接口,允許在 SQL 查詢時使用 select 註解將參數化類型資料傳遞到介面。
  • 查詢可以在任何一種模式下執行,例如連接模式或斷開連接模式。如果任何函數進入連接模式,那麼在這種情況下資料集就像一個結果集。
  • 如果任何函數進入斷開連接的資料集,那麼在這種情況下,函數將反映為 CachedRowSet。
  • 如今,Java 資料集也出現在機器學習的凝膠中,因為機器學習的整個領域基本上都處理大量數據,這使得需要對這些數據進行查看和操作。
  • Dataset Java 在 Spark with Java 等 API 的幫助下利用任何此類操作,而 Spark 又提供了一些內建程式庫和套件,使場景在兩者之間完美匹配。
  • 事實上,Dataset Java 還有助於建立許多模式,並提供處理sql 介面的視圖,這有助於提供許多異常和連接問題,在這些問題之前捕獲這些問題有助於使整個實施和開發更安全地避免安全漏洞.
  • 借助直接插入 csv 檔案、另一個資料儲存、用於表示的圖形資料庫,使用資料集 java 從程式碼庫進行查詢,所有這些整合都為資料集 java 的使用提供了優勢和簡單性。

建立新的 Java 資料集

由於資料集用於反映和展示場景的許多實例,因此,它是透過以下方式建立的:

代碼:

Dataset dt = new DefaultDataset (); // creation syntax for the dataset
for (b=0, b<8, b++) // condition setting
{
Instnc inst_1 = Instnc.randomInstnc(12); // defining the instance for the dataset
Dt.add(inst_1); //adding the instance for the dataset
}
登入後複製

建立資料集後,有多種方法可以將資料集與選擇註釋同步,該註釋在配置資料集用於操作內容然後將元素設定為斷開連接格式時套用。如果資料以任何格式存儲,然後要求同步,那麼會有一些方法可以做到這一點,即利用 Dataset.sync 方法來同步儲存在某些第三方供應商中的整個資料以進行操作。

資料內的修改是透過使用其上的操作來完成的,這本質上是原子的。它還使用 Dataset.sync 方法,用於將修改的資料集傳播到指定位置或資料儲存。如果在這種情況下,建立的資料集與儲存位置之間的同步失敗,它將開始拋出 SQLDataSetSyncException,這是對 DataSet.sync 的激發的結果。

DataSet Java 範例

下面給出的是 Java DataSet 的範例:

範例#1

該程式用於在對其執行 SQL 查詢時建立和迭代表示汽車名稱和汽車特徵的整個資料集。

代碼:

public class Cars_dtset {
public String car_name;
public String car_description;
public int car_no;
}
interface Actual_Query extends Bs_Query {
@Select("select car_name, car_description, car_no from Cars_dtset")
DataSet<Cars_dtset> getAllCars_dtset();
}
Actual_Query mq_0 = con.createQueryObject(Actual_Query.class);
DataSet rows = mq_0.getAllCars_dtset();
for (Cars_dtset mq_0: rows) {
System.out.println("CarName = " + mq_0.car_name);
System.out.println("CarDescription = " + mq_0.car_description);
}
登入後複製

說明:

  • 在這種情況下,基本上,目標是透過導航整個數據集來操作數據,這是一個子接口,允許整個應用程式瀏覽數據集物件。

範例#2

下面的程式碼片段表示在定義的資料集中插入行的操作。

代碼:

DataSet rows = mq_0.getAllCars_dtset();
Cars_dtset newCar = new Cars_dtset();
newCar.car_name="Porsche_cv ";
newCar.car_description="It’s a classic_range_of_collection. ";
rows.insert(newCar);
登入後複製

說明:

  • 在上述場景中,主要目的是透過使用表名建立選擇註解來建立相同的實例,從而將行插入到現有資料集中。

範例 #3

下面的程式碼片段表示在表中插入資料的操作,以便透過執行相同的操作在 select 子句中修改資料。

代碼:

DataSet rows = mq_0.getAllCars_dtset();
for (Cars_dtset mq_0: rows) {
if (mq_0.car_description.equals("")) {
mq_0.car_description="limborgini_car_range";
rows.modify();
}
}
登入後複製

說明:

  • In the above scenario, there is a provision to update rows within a dataset by positioning the row for modifying the data and then calling the modify method for doing the same on the dataset.
  • The dataset can be disconnected but then it can keep the specified element as a resource as well.

Example #4

This program demonstrates the deletion of rows from within the dataset in the case where any element within the dataset row is not required or is irrelevant.

Code:

DataSet rows = mq_0.getAllCars_dtset();
for (Cars_dtset mq_0: rows) {
if (mq_0.car_description.equals("abc")) {
rows.delete();
}
}
登入後複製

Explanation:

Deletion plays an important role when it comes to manipulation of data within a dataset as sometimes the scenario arises where the data is irrelevant or throwing continuous exceptions than in that case there are chances of getting the SQLDataSetSync exceptions at that time deletion can be the utmost requirement for solving the error or any troubleshooting issue that might arise at the time of implementation or development, thus leading to bugs.

Conclusion

DataSet Java is a good add on with respect to Java when it comes to deal with huge sets of data and instances as nowadays it is used and blend with lots of new technologies like machine learning, AWS and normal enterprise application as it gives the developers and programmers the ability to query with the operations already present as part of the library and syntax.

以上是Java資料集的詳細內容。更多資訊請關注PHP中文網其他相關文章!

相關標籤:
來源:php
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板
關於我們 免責聲明 Sitemap
PHP中文網:公益線上PHP培訓,幫助PHP學習者快速成長!