JDBC and ADO.Net: API Comparison

What is the analogy between objects found in JDBC and those found in ADO.Net ?

I know that the object model in JDBC and ADO.Net is not quite the same, but I think some of them can be found among them (and the key differences that are worth saying).

This would be useful for those who know one API and want to know another, which can serve as a starting point, or to avoid misunderstandings caused by assumptions about the API that they want to learn.

For example: What is an ADO.Net object that provides the same functionality / behavior as a JDBC ResultSet? same for PreparedStatemes etc ...

+6
comparison jdbc
source share
2 answers

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
+5
source share

Not very thorough with jdbc, but from what I know, ADO.NET follows a disabled architecture, where the connection is established only for the time when the request needs to be executed or read. After reading the reader, the connection can be closed. Data caching is achieved using datasets and data adapters. In ADO.NET, only one reader is allowed per connection. Although a disconnected architecture is certainly possible in jdbc, it is built on the concept of having a live connection, where you can have multiple readers per connection.

Another difference of the API is that the jdbc function is built in to get the last inserted identifier , while ADO is missing.

Also read a good comparison of data caching in ADO and jdbc.

+2
source share

All Articles