JDBC学习一 基础 一个简单的增删该查例子
?????+ rs.getString("name") + "\n age:" + rs.getInt("age")
?????+ "\n sex" + rs.getString("sex") + "\n brithday:"
?????+ rs.getDate("brithday"));
??}
??// 关闭资源
??jdbcUtil02.free(st, conn, rs);
?}
?//添加
?@Test
?public void insert() throws Exception {
??Connection conn = jdbcUtil02.getInstance().getConnection();
??Statement st = conn.createStatement();
??String sql = "insert into user values(4,'name1',20,'nan','1992-12-28')";
??int i = st.executeUpdate(sql);
??System.out.println("i = "+i);
??
?}
?//修改
?@Test
?public void update() throws Exception {
??Connection conn = jdbcUtil02.getInstance().getConnection();
??Statement st = conn.createStatement();
??String sql = "update user set age = 30 where id = 1";
??int i = st.executeUpdate(sql);
??
?}
?//删除
?@Test
?public void delete() throws Exception {
??Connection conn = jdbcUtil02.getInstance().getConnection();
??Statement st = conn.createStatement();
??String sql = "delete from user where id > 2";
??int i = st.executeUpdate(sql);
??
?}
?
}