今天完成内容:
开发家庭小账本
1.编写代码
public List<User> ResearchName(String name){
List<User> list = new ArrayList<User>();
Connection conn = DbHelper.getConnection();
String sql = "select * from userno where username = ?";
try {
PreparedStatement pst = conn.prepareStatement(sql);
pst.setString(1, name);
ResultSet rst = pst.executeQuery();
while(rst.next()) {
User user = new User();
user.setId(rst.getInt("id"));
user.setUsername(rst.getString("username"));
user.setUserused(rst.getString("userused"));
user.setUsermoney(rst.getString("usermoney"));
user.setUsedate(rst.getDate("usedate"));
list.add(user);
}
rst.close();
pst.close();
} catch (SQLException e) {
// TODO 自动生成的 catch 块
e.printStackTrace();
}
return list;
}
public User ResearchId(int id) {
Connection conn = DbHelper.getConnection();
String sql = "select * from userno where id = ?";
ResultSet rst = null;
User user = new User();
try {
PreparedStatement pst = conn.prepareStatement(sql);
pst.setInt(1, id);
rst = pst.executeQuery();
while(rst.next()) {
user.setId(rst.getInt("id"));
user.setUsername(rst.getString("username"));
user.setUserused(rst.getString("userused"));
user.setUsermoney(rst.getString("usermoney"));
user.setUsedate(rst.getDate("usedate"));
}
rst.close();
pst.close();
} catch (SQLException e) {
// TODO 自动生成的 catch 块
e.printStackTrace();
}
// TODO 自动生成的方法存根
return user;
}
public List<User> showAll(){
List<User> list = new ArrayList<User>();
Connection conn = DbHelper.getConnection();
String sql = "select * from userno";
try {
PreparedStatement pst = conn.prepareStatement(sql);
ResultSet rst = pst.executeQuery();
while(rst.next()) {
User user = new User();
user.setId(rst.getInt("id"));
user.setUsername(rst.getString("username"));
user.setUserused(rst.getString("userused"));
user.setUsermoney(rst.getString("usermoney"));
user.setUsedate(rst.getDate("usedate"));
list.add(user);
}
rst.close();
pst.close();
} catch (SQLException e) {
// TODO 自动生成的 catch 块
e.printStackTrace();
}
return list;
}
遇到问题:
无,可以实现查询功能
明日目标:
学习Android studio的开发