1.加载驱动
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
2.建立连接
Connection conn = DriverManager.getConnection("jdbc:sqlserver://localhost:1443;DatabaseName=epet","sa","sa");
3.执行sql语句
PreparedStatement pst = conn.prepareStatement("select * from Pet where name = ?");
pst.setString(1,getName());
ResultSet rs = pst.executeQuery();
while(rs.next()){
String name = rs.getString("name");
}
4.释放资源
conn.close();
pst.close();
rs.close();