• 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);
  • 相关阅读:
    数据库数据格式化之Kettle Spoon
    NopCommerce开源项目中很基础但是很实用的C# Helper方法
    oracle 两个逗号分割的字符串 如何判断是否其中有相同值
    MongoDB+MongoVUE安装及入门
    C#中Dictionary<TKey,TValue>排序方式
    kettle的基本介绍
    Kettle能做什么?
    oracle like 条件拼接
    loading加载和layer.js
    关于bootstrap的treeview不显示多选(复选框)的问题,以及联动选择的问题,外加多选后取值
  • 原文地址:https://www.cnblogs.com/cnmotive/p/3128054.html
Copyright © 2020-2023  润新知