views:

18

answers:

1

What are the analogies between the objects found in JDBC and the ones found in ADO.Net?

I know the object model in JDBC and ADO.Net are not exactly the same, but I think some analogies can be found among them (and key differences worth stating).

That would be useful for those who knows one API and wants to learn the other, serving as a starting point maybe, or avoiding misunderstandings caused by assumptions one makes about the API that wants to learn.

e.g.: Which is the ADO.Net object that provides the same functionality/behavior as the JDBC ResultSet? the same for PreparedStatemes, and so on...

+1  A: 

Here is a simple sequence for ADO.NET:

// 1. create a connection
SqlConnection conn = new SqlConnection(xyz)
// 2. open the connection
conn.Open();
// 3. create a command
 SqlCommand cmd = new SqlCommand("select * from xyz", conn);
// 4. execute and receive the result in a reader
SqlDataReader rdr = cmd.ExecuteReader();
// 5. get the results
while (rdr.Read())
{
//dosomething
}

Here is a simple sequence for JDBC:

// 1. create a connection
Connection con = DriverManager.getConnection(xyz);
// 2. create a statement     
Statement stmt = con.createStatement();
// 3. execute and receive results in a result set
ResultSet rs = stmt.executeQuery("SELECT * from xyz");
// 4. Get the results
while (rs.next()) 
{
// do something
}

And here is the analogy (ADO.NET => JDBC):

SqlConnection => Connection
SqlCommand => Statement
SqlDataReader => ResultSet
Amr Hesham Abdel Majeed
What about JDBC's PreparedStatements, ADO.Net's DataSet, ...?
Toto

related questions