Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DataTable equivalent in Java [duplicate]

Is there a C# DataTable equivalent in Java?

like image 684
Ajay Avatar asked Aug 27 '09 10:08

Ajay


People also ask

Is there a DataTable in Java?

Java DataTable is available on Maven.

How to make a DataTable in Java?

Create a new DocumentBuilder object on your Document. Start a new table using DocumentBuilder. If we want to insert the names of each of the columns from our DataTable as a header row then iterate through each data column and write the column names into a row in the table. Iterate through each DataRow in the DataTable.

What is a DataTable in Java?

A data table contains relational data that can be referenced as follows: from Java code through wrappers as Java arrays. through OpenL Tablets run-time API as a field of the Rules class instance.

How to add data in DataTable in Java?

After you create a DataTable and define its structure using columns and constraints, you can add new rows of data to the table. To add a new row, declare a new variable as type DataRow. A new DataRow object is returned when you call the NewRow method.


2 Answers

A similar question that has been asked recently. ResultSet certainly is not a direct equivalent as it only works with an active connection to the database while a DataTable can be used "offline".

From personal experience I would say there is no direct equivalent in Java (haven't tried javax.sql.rowset.WebRowSet, though). You either go with plain SQL and java.sql.ResultSet is your friend. Or you use some ORM tool like Hibernate, Cayenne, Toplink to name a few. Or you build your own (not that I encourage this, but I think on more than one project that has been done successfully).

like image 147
Robert Petermeier Avatar answered Oct 02 '22 09:10

Robert Petermeier


Give this framework a try:

Casper Datasets

Its a in-memory dataset library that is generic and also type safe. You can:

  • Pull data automatically from relational queries (or from any other programmatic source),
  • Issue complex, chained queries against the dataset,
  • Optimize a given dataset by specifying indexes on particular columns.

Its easy-to-use and doesn't have any significant dependencies. Its also compliant with java.sql.ResultSet, so its possible to integrate this easily into any existing apps that query against relational database

like image 38
jli_123 Avatar answered Oct 02 '22 09:10

jli_123