jdbc连接数据库代码 【复习一下执行流程】
static final String url = "jdbc:mysql://localhost:3306/lib?useUnicode=true&characterEconding=UTF-8";
static final String user = "root";//数据库的用户名
static final String password = "root";//数据库的密码
static Connection conn = null;
static Statement st = null;
static ResultSet rs = null;
Class.forName("com.mysql.jdbc.Driver");
conn = DriverManager.getConnection(url, user, password);
String sql = "select * from manager where name = ? and password = ? ";
st = conn.createStatement();
st.setString(1, user.getName());
st.setString(2, user.getPassword());
rs = st.executeQuery();
try {
while (rs.next()) {
.....对结果集的操作......
// 关闭数据库连接
ps.close();