admin 管理员组

文章数量: 887021


2024年2月6日发(作者:杰克琼斯旗下三大品牌)

package ;/** * 图书信息 * @author admin * */public class Book { private int book_id;//图书编号 private String book_name;//图书姓名 private String book_writer;//作者 private String book_publish;//出版社 private String book_status;//状态

public Book() { super(); }

public Book(int book_id) { super(); _id = book_id; } public Book(int book_id, String book_name, String book_writer, String book_publish, String book_status) { super(); _id = book_id; _name = book_name; _writer = book_writer; _publish = book_publish; _status = book_status; } public int getBook_id() { return book_id; } public void setBook_id(int book_id) { _id = book_id; } public String getBook_name() { return book_name; } public void setBook_name(String book_name) { _name = book_name; } public String getBook_writer() { return book_writer; } public void setBook_writer(String book_writer) { _writer = book_writer; } public String getBook_publish() { return book_publish; } public void setBook_publish(String book_publish) { _publish = book_publish; } public String getBook_status() { return book_status; } public void setBook_status(String book_status) { _status = book_status; }}

Dao包下的数据库访问层,以Book为例package ;import tion;import edStatement;import Set;import ;import Null;/** *

* @author admin * */public class BookDao { /** * 查询图书 * @param con * @param book * @return * @throws Exception */ public ResultSet query(Connection con,Book book)throws Exception{ ResultSet resultUser = null; StringBuffer sql = new StringBuffer("select * from book");

//数据库模糊查询 if(mpty(k_name())) { (" and book_name like '%"+k_name()+"%'"); }

if(mpty(k_writer())) { (" and book_writer like '%"+k_writer()+"%'"); }

if(mpty(k_publish())) { (" and book_publish like '%"+k_publish()+"%'"); }

PreparedStatement pstmt = (PreparedStatement)eStatement(ng().replaceFirst("and", "where")); return eQuery();

} /** * 查询图书 * @param con * @param book * @return * @throws Exception */ public ResultSet query2(Connection con,Book book)throws Exception{ ResultSet resultUser = null; String sql = "select * from book where book_id=?"; PreparedStatement pstmt = (PreparedStatement)eStatement(sql);

(1, k_id());

return eQuery(); } /** * 图书信息修改 * @param con * @param book * @return

import ;import tTableModel;import o;import formationDao;import ;import formation;import t;import Null;import dapter;import vent;public class QueryBookInterface extends JFrame { private JPanel contentPane; private JTextField book_nameTxt; private JTextField book_writerTxt; private JTextField book_publishTxt; private Connect conutil= new Connect(); private BookDao bookDao= new BookDao(); private BookInformationDao bookInformationDao = new BookInformationDao(); public static String readerName; public static String adminName; /** * Launch the application. */ JFrame frame = new JFrame(); private JTable bookTable; private JPanel panel; private JLabel lblNewLabel; private JButton borrowButton; private JLabel label; private JLabel label_4; private JLabel label_5; private JTextField book_RBnameTxt; private JTextField book_RBwriterTxt; private JTextField book_RBpublishTxt; private JTextField book_RBstatusTxt; private JButton returnButton; private JTextField book_RBidTxt; /** * Create the frame. */ public QueryBookInterface() { setTitle("u56FEu4E66u7684u67E5u8BE2uFF0Cu501Fu9605uFF0Cu5F52u8FD8"); setDefaultCloseOperation(_ON_CLOSE); setBounds(100, 100, 920, 686); contentPane = new JPanel(); der(new EmptyBorder(5, 5, 5, 5)); setContentPane(contentPane);

JButton queryButton = new JButton("u67E5u8BE2"); ionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { queryBookTable(e); } });

JLabel label_1 = new JLabel("u56FEu4E66u540Du5B57:");

JLabel label_2 = new JLabel("u56FEu4E66u4F5Cu8005uFF1A");

JLabel label_3 = new JLabel("u51FAu7248u793EuFF1A");

book_nameTxt = new JTextField(); book_umns(10);

book_writerTxt = new JTextField(); book_umns(10);

book_publishTxt = new JTextField(); book_umns(10);

JScrollPane scrollPane = new JScrollPane();

panel = new JPanel(); GroupLayout gl_contentPane = new GroupLayout(contentPane); gl_izontalGroup( gl_ParallelGroup(G) .addGroup(gl_SequentialGroup() .addGroup(gl_ParallelGroup(G) .addGroup(gl_SequentialGroup() .addGap(42) .addGroup(gl_ParallelGroup(G) .addComponent(label_2) .addComponent(label_1) .addComponent(label_3)) .addGap(28) .addGroup(gl_ParallelGroup(G) .addComponent(queryButton, RED_SIZE, 132, RED_SIZE) .addGroup(gl_ParallelGroup(G, false) .addComponent(book_nameTxt) .addComponent(book_writerTxt) .addComponent(book_publishTxt, RED_SIZE, 286, RED_SIZE)))) .addGroup(gl_SequentialGroup() .addContainerGap() .addComponent(panel, RED_SIZE, 435, RED_SIZE))) .addGap(34) .addComponent(scrollPane, RED_SIZE, 388, RED_SIZE) .addContainerGap(21, _VALUE)) ); gl_ticalGroup( gl_ParallelGroup(NG) .addGroup(gl_SequentialGroup() .addGroup(gl_ParallelGroup(G) .addGroup(gl_SequentialGroup() .addGap(42) .addComponent(scrollPane, T_SIZE, 566, _VALUE)) .addGroup(gl_SequentialGroup() .addGap(84) .addGroup(gl_ParallelGroup(G) .addComponent(label_1) .addComponent(book_nameTxt, RED_SIZE, T_SIZE, RED_SIZE)) .addPreferredGap(D, 52, _VALUE) .addGroup(gl_ParallelGroup(NE) .addComponent(label_2) .addComponent(book_writerTxt, RED_SIZE, T_SIZE, RED_SIZE)) .addGap(51) .addGroup(gl_ParallelGroup(NE) .addComponent(label_3) .addComponent(book_publishTxt, RED_SIZE, T_SIZE, RED_SIZE)) .addGap(18) .addComponent(queryButton, RED_SIZE, 36, RED_SIZE) .addPreferredGap(D) .addComponent(panel, RED_SIZE, 277, RED_SIZE) .addGap(11))) .addGap(21)) );

lblNewLabel = new JLabel("u56FEu4E66u540Du5B57uFF1A");

borrowButton = new JButton("u501Fu9605"); ionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { borrowBook(); } });

label = new JLabel("u4F5Cu8005uFF1A");

label_4 = new JLabel("u51FAu7248u793EuFF1A");

label_5 = new JLabel("u72B6u6001uFF1A");

book_RBnameTxt = new JTextField(); book_umns(10);

book_RBwriterTxt = new JTextField(); book_umns(10);

book_RBpublishTxt = new JTextField(); book_umns(10);

book_RBstatusTxt = new JTextField(); book_umns(10);

returnButton = new JButton("u5F52u8FD8"); ionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { returnBook(); } });

JLabel label_6 = new JLabel("u7F16u53F7uFF1A");

book_RBidTxt = new JTextField(); book_umns(10); GroupLayout gl_panel = new GroupLayout(panel); gl_izontalGroup( gl_ParallelGroup(G) .addGroup(gl_SequentialGroup() .addGap(28) .addGroup(gl_ParallelGroup(G) .addComponent(lblNewLabel) .addComponent(label) .addComponent(label_4) .addComponent(label_5) .addComponent(label_6)) .addGap(32) .addGroup(gl_ParallelGroup(NG) .addComponent(book_RBidTxt, T_SIZE, 286, _VALUE) .addGroup(gl_SequentialGroup() .addComponent(borrowButton) .addPreferredGap(D, 160, _VALUE) .addComponent(returnButton)) .addComponent(book_RBwriterTxt, G, 286, 286, _VALUE) .addComponent(book_RBnameTxt, T_SIZE, 286, _VALUE) .addComponent(book_RBpublishTxt, G, 286, 286, _VALUE) .addComponent(book_RBstatusTxt, G, 286, 286, _VALUE)) .addContainerGap()) ); gl_ticalGroup( gl_ParallelGroup(G) .addGroup(gl_SequentialGroup()

.addGroup(gl_SequentialGroup() .addGap(22) .addGroup(gl_ParallelGroup(NE) .addComponent(lblNewLabel) .addComponent(book_RBnameTxt, RED_SIZE, T_SIZE, RED_SIZE)) .addGap(24) .addGroup(gl_ParallelGroup(NE) .addComponent(label) .addComponent(book_RBwriterTxt, RED_SIZE, T_SIZE, RED_SIZE)) .addGap(18) .addGroup(gl_ParallelGroup(NE) .addComponent(label_4) .addComponent(book_RBpublishTxt, RED_SIZE, T_SIZE, RED_SIZE)) .addGap(18) .addGroup(gl_ParallelGroup(NE) .addComponent(label_5) .addComponent(book_RBstatusTxt, RED_SIZE, T_SIZE, RED_SIZE)) .addGap(18) .addGroup(gl_ParallelGroup(NG) .addComponent(book_RBidTxt, RED_SIZE, T_SIZE, RED_SIZE) .addComponent(label_6)) .addPreferredGap(D, 17, _VALUE) .addGroup(gl_ParallelGroup(NE) .addComponent(returnButton) .addComponent(borrowButton)) .addContainerGap()) ); out(gl_panel);

bookTable = new JTable(); seListener(new MouseAdapter() { @Override public void mousePressed(MouseEvent e) { bookTableMousePressed(e); } }); lsViewportHeight(true); el(new DefaultTableModel( new Object[][] { }, new String[] { "u7F16u53F7", "u56FEu4E66u540Du5B57", "u4F5Cu8005", "u51FAu7248u793E", "u72B6u6001" } ) { boolean[] columnEditables = new boolean[] { false, false, false, false, false }; public boolean isCellEditable(int row, int column) { return columnEditables[column]; } }); wportView(bookTable); out(gl_contentPane); ble(new Book());//初始化图书信息 } /** * 归还图书函数 */ protected void returnBook() { String bookId = _t(); String bookName = _t(); String bookPublish =_t(); String bookWriter = _t(); String bookStatus = _t();

} /** * 初始化图书信息 * @param book */ private void fillTable(Book book) { DefaultTableModel dtm = (DefaultTableModel) el(); Count(0); Connection con = null; try { con = (); ResultSet rs = (con, book); while(()) { Vector v = new Vector(); (ing("book_id")); (ing("book_name")); (ing("book_writer")); (ing("book_publish")); if(ing("book_status").equals("1")) { ("已借出"); }else { ("未借出"); } (v); } } catch (Exception e) { tackTrace(); }finally { try { on(con); } catch (Exception e) { tackTrace(); } } }}


本文标签: 图书 旗下 信息 数据库