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);
  • 相关阅读:
    所谓经济现象
    高旻寺德林老和尚开示
    3Delight NSI: A Streamable Render API
    Play vue.js with constant value in SailsJS
    天魔心法之——识人篇
    对国内IoT的展望
    对国内AR产业的预言
    简评某中国工程师嫌疑窃取苹果自动驾驶技术
    评估人类的金三角模型
    Odoo 进销存报表现已开源
  • 原文地址:https://www.cnblogs.com/cnmotive/p/3128054.html
Copyright © 2011-2022 走看看