zoukankan      html  css  js  c++  java
  • Swing入门级项目全程实录第4讲

      惯例广告一发,对于初学真,真的很有用www.java1234.com,去试试吧!

    1、创建BookTypeManageInterFrm
         
         1.1创建BookTypeManageInterFrm并修改属性
     
         1.2添加jLable、jTextField、jButton、jTable控制,并修改属性及美化
     
    2、在MainFrm中添加点击事件BookTypeManageInterFrm
         BookTypeManageInterFrm BookTypeManageInterFrm = new BookTypeManageInterFrm();
            BookTypeManageInterFrm.setVisible(true);
            jp_table.add(BookTypeManageInterFrm);

    3、在bookTypeDao中增加bookTypeList方法

        public ResultSet bookTypeList(Connection con) throws Exception{
            String sql="select * from t_booktype";
            PreparedStatement pstmt=con.prepareStatement(sql);
            return pstmt.executeQuery();
        }
    4、在BookTypeManageInterFrm中增加fillTable方法
       public void fillTable() {
            DefaultTableModel dtm=(DefaultTableModel) jt_table.getModel();
            Connection con=null;
            try {
                con=dbUtil.getCon();
                ResultSet rs=bookTypeDao.bookTypeList(con);
                while(rs.next()){
                    Vector v=new Vector();
                    v.add(0,rs.getString("id"));
                    v.add(1,rs.getString("bookTypeName"));
                    v.add(2,rs.getString("bookTypeDesc"));
                    dtm.addRow(v);
                }
            } catch (Exception e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }finally{
                try {
                    dbUtil.closeCon(con);
                } catch (Exception e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }
            
        }

     5、增加条件查询

          5.1修改查询增加条件查询
        public ResultSet bookTypeList(Connection con,BookType bookType) throws Exception{
            StringBuffer sb=new StringBuffer("select * from t_booktype");
            if(StringUtil.isNotEmpty(bookType.getBookTypeName())){
                sb.append(" and bookTypeName like'%"+bookType.getBookTypeName()+"%'");
            }
            PreparedStatement pstmt=con.prepareStatement(sb.toString().replaceFirst("and", "where"));
            return pstmt.executeQuery();
        }

     6、在fillTable方法增加清空

    dtm.setRowCount(0);
  • 相关阅读:
    记一次DRF问题排障
    贷款
    wpf 手指触摸图片放大缩小 设置放大缩小值
    wpf下的图片放大缩小
    WPF 鼠标移动到图片变大,移开还原,单击触发事件效果
    导出压缩
    Sql Server 数据库分页存储过程书写
    Asp.Net Core MVC传值 Asp.Net Core API 前台写法
    MVC下拉框
    Dapper和EF学习
  • 原文地址:https://www.cnblogs.com/cnmotive/p/3128054.html
Copyright © 2011-2022 走看看