tags:

views:

295

answers:

3

Is there a C# DataTable equivalent in Java?

+1  A: 

Consider using a

java.sql.ResultSet

Statement s = conn.createStatement();
ResultSet rs = s.executeQuery("select * from generic_table");
ResultSetMetaData md = rs.getMetaData();
JL
but here, I need to traverse, using resultSet.next(). I cannot say, give me the values of column 1 or give me the value at (2,2)
Ajay
A: 

No - not in the standard libraries (i.e. the Java API).

oxbow_lakes
+1  A: 

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).

Robert Petermeier