今天完成内容:
开发家庭小账本:选择项
1.编写代码
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"));
user.setUsed(rst.getString("used"));
}
rst.close();
pst.close();
} catch (SQLException e) {
// TODO 自动生成的 catch 块
e.printStackTrace();
}
// TODO 自动生成的方法存根
return user;
}
public int IncomeSum(){
Connection conn = DbHelper.getConnection();
String sql = "select * from userno where used = ?";
String snum = null;
PreparedStatement pst = null;
int isum = 0;
try {
pst = conn.prepareStatement(sql);
pst.setString(1, "收入");
ResultSet rst = pst.executeQuery();
while(rst.next()) {
User user = new User();
user.setUsermoney(rst.getString("usermoney"));
snum = user.getUsermoney();
isum = isum + Integer.parseInt(snum);
}
rst.close();
pst.close();
} catch (SQLException e) {
// TODO 自动生成的 catch 块
e.printStackTrace();
}
return isum;
}
public int ExpendSum(){
Connection conn = DbHelper.getConnection();
String sql = "select * from userno where used = ?";
int esum = 0;
String snum = null;
try {
PreparedStatement pst = conn.prepareStatement(sql);
pst.setString(1, "支出");
ResultSet rst = pst.executeQuery();
while(rst.next()) {
User user = new User();
user.setUsermoney(rst.getString("usermoney"));
snum = user.getUsermoney();
esum = esum + Integer.parseInt(snum);
}
rst.close();
pst.close();
} catch (SQLException e) {
// TODO 自动生成的 catch 块
e.printStackTrace();
}
return esum;
}
遇到问题:
解决大部分问题,还有一些细节未修改
明日目标:
学习Android studio的开发