每周总结

写了自测题中的图书管理系统,对写代码的思路大概条理清楚了,但是熟练度还是不够

public boolean delete(int idr, int idb, String time) {
String sql = "delete from jieyue where idr='" + idr + "' and idb='" + idb + "' and date='" + time + "'";
boolean f = false;
Connection conn = DBUtil_reader.getConnection();
PreparedStatement st = null;
try {
st = conn.prepareStatement(sql);
st.executeUpdate(sql);
f = true;
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
DBUtil_reader.close(conn);
DBUtil_reader.close(st);
}
return f;
}

public boolean updateday(book book) {
int a = book.getNumber() - 1;
String sql = "update book set number='" + a + "' where id = '" + book.getId() + "'";
Connection conn = DBUtil_book.getConnection();
boolean f = false;
PreparedStatement st = null;
try {
st = conn.prepareStatement(sql);
st.executeUpdate(sql);
f = true;
} catch (Exception e) {
e.printStackTrace();
// TODO: handle exception
} finally {
DBUtil_book.close(conn);
DBUtil_book.close(st);
}
return f;
}

public boolean updateday2(book book) {
int a = book.getNumber() + 1;
String sql = "update book set number='" + a + "' where id = '" + book.getId() + "'";
Connection conn = DBUtil_book.getConnection();
boolean f = false;
PreparedStatement st = null;
try {
st = conn.prepareStatement(sql);
st.executeUpdate(sql);
f = true;
} catch (Exception e) {
e.printStackTrace();
// TODO: handle exception
} finally {
DBUtil_book.close(conn);
DBUtil_book.close(st);
}
return f;
}

public List<book> select() {
String sql = "select * from book";
Connection connection = DBUtil_book.getConnection();
PreparedStatement st = null;
List<book> list = new ArrayList<>();
ResultSet rs = null;
book stuid = null;
try {
st = connection.prepareStatement(sql);
st.executeQuery(sql);
rs = st.executeQuery(sql);
while (rs.next()) {
System.out.println("1");
int id = rs.getInt("id");
String name = rs.getString("name");
String peo = rs.getString("peo");
String chuban = rs.getString("chuban");
int number = rs.getInt("number");
stuid = new book(id, name, peo, chuban, number);
System.out.println("2");
list.add(stuid);
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
DBUtil_book.close(rs);
DBUtil_book.close(st);
DBUtil_book.close(connection);
}
return list;
}

原文地址:https://www.cnblogs.com/buxiang-Christina/p/14159124.html