mmu*_*lva 6 comparison ado.net jdbc
在JDBC中找到的对象和ADO.Net中找到的对象之间有什么类比?
我知道JDBC和ADO.Net中的对象模型并不完全相同,但我认为可以在它们中找到一些类比(以及值得说明的关键差异).
这对于那些知道一个API并希望学习另一个API的人来说非常有用,可能是一个起点,或者避免因为想要学习的API所做的假设而导致的误解.
例如:哪个ADO.Net对象提供与JDBC ResultSet相同的功能/行为?同样适用于PreparedStatemes,依此类推......
这是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 }
这是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 }
这是类比(ADO.NET => JDBC):
SqlConnection => Connection SqlCommand => Statement SqlDataReader => ResultSet
归档时间: |
|
查看次数: |
2820 次 |
最近记录: |