|
用戶登錄界面
當(dāng)用戶進入系統(tǒng)時,圖書管理員根據(jù)自己的身份信息,輸入具有唯一標(biāo)識的用戶名和密碼,進行登陸;若輸入出現(xiàn)錯誤,可清空數(shù)據(jù),重新進行輸入。
登錄界面
具體功能實現(xiàn)代碼:
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;
}
圖書類別管理界面包括對圖書類別的添加與維護功能,為了頁面的簡潔性與操作的便利性,將圖書類別的查詢、修改與刪除操作統(tǒng)一放在了維護功能內(nèi)。在圖書類別添加界面,在添加完類別與類別的簡單描述之后,數(shù)據(jù)庫將通過insert語句,完成對圖書類別的添加;在維護功能頁面,數(shù)據(jù)庫將通過select語句、update語句、delete語句分別對圖書類別進行查詢、修改、刪除操作
圖書類別維護界面
具體功能實現(xiàn)代碼:
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();
}
}
圖書信息管理界面
圖書信息管理界面包括對圖書信息的添加與維護功能,為了頁面的簡潔性與操作的便利性,將圖書信息的查詢、修改與刪除操作統(tǒng)一放在了維護功能內(nèi)。在圖書信息添加界面,在添加完圖書的名稱、作者、價格等信息后,數(shù)據(jù)庫將通過insert語句,完成對圖書信息的添加;在維護功能頁面,數(shù)據(jù)庫將通過select語句、update語句、delete語句分別對圖書信息進行查詢、修改、刪除操作。
具體功能實現(xiàn)代碼:
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();
}
}
功能界面實現(xiàn)原理
系統(tǒng)整體使用swing框架,若要主界面添加菜單,則需要添加菜單空間menu和標(biāo)簽控件lable,然后在init方法內(nèi)設(shè)置各項屬性即可;若要在原窗體內(nèi)添加對象,則需先在init方法里添加所需控件,然后實例化對象,最后用代碼設(shè)置各項屬性;若要添加一個彈出式窗體,則先需將菜單項做好,加入一個監(jiān)聽事件處理器,被彈出窗體要以新建源文件的形式編寫(新建Java類),并添加一個事件處理方法,然后在構(gòu)造方法里調(diào)用動態(tài)加載的init方法,,再在這個動態(tài)加載方法里添加要顯示的內(nèi)容即可。
數(shù)據(jù)庫實現(xiàn)
系統(tǒng)與數(shù)據(jù)庫的成功連接和搭建,是該系統(tǒng)能夠順利實現(xiàn)其各個模塊功能的重要環(huán)節(jié),這個環(huán)節(jié)中利用Sqlyog建立連接并新建用戶表、圖書類別管理表、圖書信息管理表后,再通過使用JDBC等各項技術(shù),實現(xiàn)了系統(tǒng)與數(shù)據(jù)庫的連接,具體代碼如下:
public class DbUtil {
private String dbUrl="";
private String dbUse |
|