13-05-18总结

1.鼠标点击事件

1 // 获取选中的行
2 int row = bookTypeTable.getSelectedRow();
3 this.idTxt.setText((String) bookTypeTable.getValueAt(row, 0));
4 this.bookTypeNameTxt.setText((String) bookTypeTable.getValueAt(row, 1));
5 this.bookTypeDecTxt.setText((String) bookTypeTable.getValueAt(row, 2));

2.数据修改

1 public int bookTypeModify(Connection con,BookType bookType) throws Exception{
2         String sql = "update t_bookType set BookTypeName=? and bookTypeDesc=? where id=? ";
3         PreparedStatement pstmt = con.prepareStatement(sql);
4         pstmt.setString(1, bookType.getBookTypeName());
5         pstmt.setString(2, bookType.getBookTypeDesc());
6         pstmt.setInt(3, bookType.getId());
7         return pstmt.executeUpdate();
8     }

3.删除数据:

1 public int bookTypeDelect(Connection con ,String id) throws Exception{
2         String sql = "delete from t_bookType where id=?";
3         PreparedStatement pstmt = con.prepareStatement(sql);
4         pstmt.setString(1, id);
5         return pstmt.executeUpdate();
6     }

4.覆写toString()方法:

1 public String toString() {
2 
3 return this.getBookTypeName();
4 
5 }

5.设置默认值,并设置id-1

1 bookType.setBookTypeName("请选择...");
2 
3 bookType.setId(-1);

查询时:

1 if(book.getBookTypeId()!=-1){
2 
3 sb.append(" and b.bookTypeId = "+book.getBookTypeId());
4 
5 }

6.多表查询解决了昨天查询操作的疑惑:

 

 1 StringBuffer sb=new StringBuffer("select * from t_book b,t_bookType bt where b.bookTypeId=bt.id");
 2         if(StringUtil.isNotEmpty(book.getBookName())){
 3             sb.append(" and b.bookName like '%"+book.getBookName()+"%'");
 4         }
 5         if(StringUtil.isNotEmpty(book.getAuthor())){
 6             sb.append(" and b.author like '%"+book.getAuthor()+"%'");
 7         }
 8         if(StringUtil.isNotEmpty(book.getSex())){
 9             sb.append(" and b.sex = '"+book.getSex()+"'");
10         }
11         if(book.getBookTypeId()!=-1){
12             sb.append(" and b.bookTypeId = "+book.getBookTypeId());
13         }
14         PreparedStatement pstmt=con.prepareStatement(sb.toString());
15         return pstmt.executeQuery();

7.debug:看代码结果 ctrl+shift+i

今天问题:查询出错,明天继续解决!

posted @ 2013-05-28 13:13  冬叶's blog  阅读(231)  评论(0)    收藏  举报