首页  >  文章  >  Java  >  Java数据集

Java数据集

WBOY
WBOY原创
2024-08-30 16:16:37403浏览

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中文网其他相关文章!

声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
上一篇:Java DatagramSocket下一篇:Java Animation