JDBC :
Connection Statement[executeUpdate(增、删、改) executeQuery(查)] ResultSet(结果集)
ADO.NET:
SqlConnection SqlCommand SqlDataReader、SqlDateAdapter 和 DateSet(断开式连接)
ExecuteNonQuery()、ExecuteScalar()、ExecuteReader()、
package zuxia.java12.JDBC1;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class FinalConnection {
//创建连接
public Connection getConnection() throws SQLException, ClassNotFoundException{
String url = "jdbc:sqlserver://localhost:1433;database=test";
String user = "sa";
String password = "123456";
String driver = "com.microsoft.sqlserver.jdbc.SQLServerDriver";
Class.forName(driver);
return DriverManager.getConnection(url, user, password);
/*
* SQLServerDriver driver = new SQLServerDriver();
* DriverManager.registerDriver(driver);
* 与
*\\String driver = "com.microsoft.sqlserver.jdbc.SQLServerDriver";
*\\Class.forName(driver);
* 等效
*/
}
//关闭连接
public void Close(ResultSet rs,Statement st,Connection con){
if(rs != null){
try {
rs.close();
} catch (SQLException e) {