久久久久久久999_99精品久久精品一区二区爱城_成人欧美一区二区三区在线播放_国产精品日本一区二区不卡视频_国产午夜视频_欧美精品在线观看免费

 找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

搜索
查看: 1454|回復: 0
收起左側

不完整 基于Java的圖書管理系統實現

[復制鏈接]
ID:1024008 發表于 2022-5-24 18:29 來自觸屏版 | 顯示全部樓層 |閱讀模式
用戶登錄界面
當用戶進入系統時,圖書管理員根據自己的身份信息,輸入具有唯一標識的用戶名和密碼,進行登陸;若輸入出現錯誤,可清空數據,重新進行輸入。
登錄界面
具體功能實現代碼:
public class UserDao {
        public User login(Connection con,User user)throws Exception{  
                User resultUser=null;            
                String sql="select * from t_user where userName=? and password=?";
                PreparedStatement pstmt=con.prepareStatement(sql);   
                pstmt.setString(1, user.getUserName());  
                pstmt.setString(2, user.getPassword());
                ResultSet rs=pstmt.executeQuery();     
                if(rs.next()){                        
                        resultUser=new User();            
                        resultUser.setId(rs.getInt("id"));
                        resultUser.setUserName(rs.getString("userName"));
                        resultUser.setPassword(rs.getString("password"));
                }
                return resultUser;   
        }   


圖書類別管理界面包括對圖書類別的添加與維護功能,為了頁面的簡潔性與操作的便利性,將圖書類別的查詢、修改與刪除操作統一放在了維護功能內。在圖書類別添加界面,在添加完類別與類別的簡單描述之后,數據庫將通過insert語句,完成對圖書類別的添加;在維護功能頁面,數據庫將通過select語句、update語句、delete語句分別對圖書類別進行查詢、修改、刪除操作
圖書類別維護界面
具體功能實現代碼:
public class BookTypeDao {
        public int add(Connection con,BookType bookType)throws Exception{
                String sql="insert into t_bookType values(null,?,?)";
                PreparedStatement pstmt=con.prepareStatement(sql);
                pstmt.setString(1, bookType.getBookTypeName());
                pstmt.setString(2, bookType.getBookTypeDesc());
                return pstmt.executeUpdate();
        }
        public ResultSet list(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();
        }
        public int delete(Connection con,String id)throws Exception{
                String sql="delete from t_bookType where id=?";
                PreparedStatement pstmt=con.prepareStatement(sql);
                pstmt.setString(1, id);
                return pstmt.executeUpdate();
        }
        public int update(Connection con,BookType bookType)throws Exception{
                String sql="update t_bookType set bookTypeName=?,bookTypeDesc=? where id=?";
                PreparedStatement pstmt=con.prepareStatement(sql);
                pstmt.setString(1, bookType.getBookTypeName());
                pstmt.setString(2, bookType.getBookTypeDesc());
                pstmt.setInt(3, bookType.getId());
                return pstmt.executeUpdate();
        }
}

圖書信息管理界面
圖書信息管理界面包括對圖書信息的添加與維護功能,為了頁面的簡潔性與操作的便利性,將圖書信息的查詢、修改與刪除操作統一放在了維護功能內。在圖書信息添加界面,在添加完圖書的名稱、作者、價格等信息后,數據庫將通過insert語句,完成對圖書信息的添加;在維護功能頁面,數據庫將通過select語句、update語句、delete語句分別對圖書信息進行查詢、修改、刪除操作。
具體功能實現代碼:
public class BookDao {
        public int add(Connection con,Book book)throws Exception{
                String sql="insert into t_book values(null,?,?,?,?,?,?)";
                PreparedStatement pstmt=con.prepareStatement(sql);
                pstmt.setString(1, book.getBookName());
                pstmt.setString(2, book.getAuthor());
                pstmt.setString(3, book.getSex());
                pstmt.setFloat(4, book.getPrice());
                pstmt.setInt(5, book.getBookTypeId());
                pstmt.setString(6, book.getBookDesc());
                return pstmt.executeUpdate();
        }
        public ResultSet list(Connection con,Book book)throws Exception{
                StringBuffer sb=new StringBuffer("select * from t_book b,t_bookType bt where b.bookTypeId=bt.id");
                if(StringUtil.isNotEmpty(book.getBookName())){
                        sb.append(" and b.bookName like '%"+book.getBookName()+"%'");
                }
                if(StringUtil.isNotEmpty(book.getAuthor())){
                        sb.append(" and b.author like '%"+book.getAuthor()+"%'");
                }
                if(book.getBookTypeId()!=null && book.getBookTypeId()!=-1){
                        sb.append(" and b.bookTypeId="+book.getBookTypeId());
                }
                PreparedStatement pstmt=con.prepareStatement(sb.toString());
                return pstmt.executeQuery();
        }
        public int delete(Connection con,String id)throws Exception{
                String sql="delete from t_book where id=?";
                PreparedStatement pstmt=con.prepareStatement(sql);
                pstmt.setString(1, id);
                return pstmt.executeUpdate();
        }
        public int update(Connection con,Book book)throws Exception{
                String sql="update t_book set bookName=?,author=?,sex=?,price=?,bookDesc=?,bookTypeId=? where id=?";
                PreparedStatement pstmt=con.prepareStatement(sql);
                pstmt.setString(1, book.getBookName());
                pstmt.setString(2, book.getAuthor());
                pstmt.setString(3, book.getSex());
                pstmt.setFloat(4, book.getPrice());
                pstmt.setString(5, book.getBookDesc());
                pstmt.setInt(6, book.getBookTypeId());
                pstmt.setInt(7, book.getId());
                return pstmt.executeUpdate();
        }
}

功能界面實現原理
    系統整體使用swing框架,若要主界面添加菜單,則需要添加菜單空間menu和標簽控件lable,然后在init方法內設置各項屬性即可;若要在原窗體內添加對象,則需先在init方法里添加所需控件,然后實例化對象,最后用代碼設置各項屬性;若要添加一個彈出式窗體,則先需將菜單項做好,加入一個監聽事件處理器,被彈出窗體要以新建源文件的形式編寫(新建Java類),并添加一個事件處理方法,然后在構造方法里調用動態加載的init方法,,再在這個動態加載方法里添加要顯示的內容即可。

數據庫實現
系統與數據庫的成功連接和搭建,是該系統能夠順利實現其各個模塊功能的重要環節,這個環節中利用Sqlyog建立連接并新建用戶表、圖書類別管理表、圖書信息管理表后,再通過使用JDBC等各項技術,實現了系統與數據庫的連接,具體代碼如下:
public class DbUtil {
        private String dbUrl="";
        private String dbUse
回復

使用道具 舉報

您需要登錄后才可以回帖 登錄 | 立即注冊

本版積分規則

小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術交流QQ群281945664

Powered by 單片機教程網

快速回復 返回頂部 返回列表
主站蜘蛛池模板: 欧美精选一区二区 | 91在线视频 | 久久亚洲二区 | 日韩免费毛片 | 91精品久久久久久久久中文字幕 | 久久99精品国产麻豆婷婷 | 国产精品一区二区三区在线 | 在线观看视频福利 | 欧美一级艳情片免费观看 | 欧美日韩亚 | 国产亚洲精品成人av久久ww | www.99热这里只有精品 | 91精品久久久久久久久中文字幕 | 欧美成人aaa级毛片在线视频 | 视频一区二区中文字幕日韩 | 日本精品一区二区在线观看 | 国产精品久久久久久久久图文区 | 欧美在线一区二区三区 | 亚洲欧美日韩精品久久亚洲区 | 亚洲精品二区 | 国产区第一页 | 久久99精品久久久久久国产越南 | av网址在线播放 | 国产一区二区三区www | 欧美在线日韩 | 国产精品18久久久久久白浆动漫 | 国产精品久久久久久久久久免费看 | 99精品一区二区 | 国产日韩欧美一区二区 | 永久精品 | 不卡一区二区三区四区 | 久久天天| 丁香久久 | 激情五月综合 | 亚洲国产成人精品女人久久久 | 中文字幕欧美日韩 | 在线免费观看毛片 | 久久涩涩| 国产一区二区三区在线视频 | 成人国产精品久久 | 日韩电影中文字幕 |