圖書查詢java代碼 查詢java圖書的詳細(xì)信息

Java使用面向?qū)ο缶幊趟季S編寫圖書管理系統(tǒng):增加,查詢,修改,刪除,退出,怎么寫?

package com.bms;

十載的中站網(wǎng)站建設(shè)經(jīng)驗(yàn),針對(duì)設(shè)計(jì)、前端、開發(fā)、售后、文案、推廣等六對(duì)一服務(wù),響應(yīng)快,48小時(shí)及時(shí)工作處理。營(yíng)銷型網(wǎng)站建設(shè)的優(yōu)勢(shì)是能夠根據(jù)用戶設(shè)備顯示端的尺寸不同,自動(dòng)調(diào)整中站建站的顯示方式,使網(wǎng)站能夠適用不同顯示終端,在瀏覽器中調(diào)整網(wǎng)站的寬度,無(wú)論在任何一種瀏覽器上瀏覽網(wǎng)站,都能展現(xiàn)優(yōu)雅布局與設(shè)計(jì),從而大程度地提升瀏覽體驗(yàn)。創(chuàng)新互聯(lián)公司從事“中站網(wǎng)站設(shè)計(jì)”,“中站網(wǎng)站推廣”以來(lái),每個(gè)客戶項(xiàng)目都認(rèn)真落實(shí)執(zhí)行。

import java.util.ArrayList;

import java.util.List;

import java.util.Scanner;

// book對(duì)象

public class Book {

private String bId; // 編號(hào)

private String bName; // 書名

// getset方法

public String getbId() {

return bId;

}

public void setbId(String bId) {

this.bId = bId;

}

public String getbName() {

return bName;

}

public void setbName(String bName) {

this.bName = bName;

}

//構(gòu)造方法

public Book() {

}

public Book(String bId, String bName) {

this.bId = bId;

this.bName = bName;

}

/*

* 增加

* */

public static ListBook add(ListBook list) {

Scanner sn = new Scanner(System.in);

System.out.print("請(qǐng)輸入編號(hào):");

String bid = sn.next();

System.out.print("請(qǐng)輸入名稱:");

String bName = sn.next();

Book book = new Book(bid, bName);

for (Book b : list) {

if (b.bId.equals(book.bId)) {

System.out.println("編號(hào)重復(fù),請(qǐng)重新輸入!");

return list;

}

}

list.add(book);

System.out.println("添加成功!");

return list;

}

/*

* 查詢

* */

public static void query(ListBook list) {

System.out.println("編號(hào)\t書名");

for (Book b : list) {

System.out.println(b.getbId() + "\t" + b.getbName());

}

}

/*

* 修改

* */

public static void update(ListBook list) {

query(list);

Scanner sc = new Scanner(System.in); // 鍵盤輸入的對(duì)象

System.out.print("請(qǐng)輸入編號(hào):");

String s = sc.next();

Integer id = null;

for (int i = 0; i list.size(); i++) {

id = list.get(i).getbId().equals(s) ? i : null;

}

if (id == null) {

System.out.println("輸入的編號(hào)不存在,請(qǐng)重新選擇!");

return;

}

System.out.print("請(qǐng)輸入新的書名:");

String newName = sc.next();

list.get(id).setbName(newName);

System.out.print("修改成功!");

}

/*

* 刪除

* */

public static void del(ListBook list) {

query(list);

Scanner sc = new Scanner(System.in); // 鍵盤輸入的對(duì)象

System.out.print("請(qǐng)輸入編號(hào):");

String s = sc.next();

for (int i = 0; i list.size(); i++) {

if (list.get(i).getbId().equals(s)) {

list.remove(i);

return;

}

}

System.out.println("輸入的編號(hào)不存在,請(qǐng)重新選擇!");

}

}

/*

* 測(cè)試*/

class Test {

public static void main(String[] args) {

ListBook bookList = new ArrayList(); // 存放所有圖書的列表

bookList.add(new Book("1", "Java 基礎(chǔ)")); // 圖書的列表添加一本圖書

System.out.print("歡迎進(jìn)入圖書管理系統(tǒng),");

boolean b = true;

while (b) {

System.out.print("請(qǐng)選擇:\n1.增加\n2.查詢\n3.修改\n4.刪除\n5.退出\n(輸入序號(hào)):");

Scanner sn = new Scanner(System.in); // 鍵盤輸入的對(duì)象

String select = sn.next();

switch (select) {

case "1":

System.out.println("您選擇了增加");

Book.add(bookList);

break;

case "2":

System.out.println("您選擇了查詢:");

Book.query(bookList);

break;

case "3":

System.out.println("您選擇了修改");

Book.update(bookList);

break;

case "4":

System.out.println("您選擇了刪除");

Book.del(bookList);

break;

case "5":

System.out.println("您選擇了退出");

b = false;

System.out.println("退出程序!");

break;

default:

System.out.println("輸入錯(cuò)誤的序號(hào),請(qǐng)重新輸入");

break;

}

}

}

}

求一個(gè)java圖書管理系統(tǒng)代碼,不需要圖形化,命令行就可以,只要求實(shí)現(xiàn)導(dǎo)入圖書,查詢,刪除

import?java.io.BufferedReader;

import?java.io.File;

import?java.io.FileReader;

import?java.util.ArrayList;

import?java.util.List;

import?java.util.Scanner;

public?class?BookWork?{

static?ListBook?data;

private?static?Scanner?input;

public?static?void?main(String[]?args)?{

if?(!initBook("d:/book.txt"))?{

System.out.println("初始圖書列表失敗?..");

return;

}

input?=?new?Scanner(System.in);

while?(true)?{

try?{

System.out.println("請(qǐng)輸入操作:");

System.out.println("1.找書??2.刪除圖書?3.退出");

int?number?=?Integer.parseInt(input.next());

if?(number?==?1)?{

findBook();

}?else?if?(number?==?2)?{

delBook();

}?else?if?(number?==?3)?{

System.out.println("退出");

break;

}?else?{

System.out.println("這個(gè)不是我要的...重來(lái)...");

System.out.println();

}

}?catch?(Exception?e)?{

e.printStackTrace();

System.out.println("這個(gè)不是我要的...重來(lái)...");

System.out.println();

}

}

}

private?static?void?delBook()?{

System.out.println("請(qǐng)輸入要?jiǎng)h除的書名或編號(hào):");

String?key?=?input.next();

if?(key?!=?null??!key.equals(""))?{

for?(Book?book?:?data)?{

if?(book.number.equals(key)?||?book.name.contains(key))?{

data.remove(book);

System.out.println("?圖書?"?+?book.toString()?+?"?已刪除");

return;

}

}

}

System.out.println("沒有您要?jiǎng)h除的");

}

private?static?void?findBook()?{

System.out.println("請(qǐng)輸入要查找的書名或編號(hào):");

String?key?=?input.next();

if?(key?!=?null??!key.equals(""))?{

for?(Book?book?:?data)?{

if?(book.number.equals(key)?||?book.name.contains(key))?{

System.out.println("找到了?圖書?"?+?book.toString());

return;

}

}

}

System.out.println("沒有您要找的");

}

private?static?boolean?initBook(String?string)?{

try?{

System.out.println("圖書導(dǎo)入中...");

System.out.println("列表文件?--?"?+?string);

File?file?=?new?File(string);

if?(!file.exists())?{

return?false;

}

data?=?new?ArrayListBook();

BufferedReader?bufferedReader?=?new?BufferedReader(new?FileReader(file));

String?line?=?"";

while?((line?=?bufferedReader.readLine())?!=?null)?{

String[]?strings?=?line.split(",");

Book?b?=?new?Book(strings[0],?strings[1]);

data.add(b);

System.out.println("導(dǎo)入"?+?b.toString());

}

}?catch?(Exception?e)?{

e.printStackTrace();

return?false;

}

return?true;

}

public?static?class?Book?{

String?number;

String?name;

public?Book(String?number,?String?name)?{

super();

this.number?=?number;

this.name?=?name;

}

@Override

public?String?toString()?{

return?"Book?[編碼:"?+?number?+?",?名稱:"?+?name?+?"]";

}

}

}

001,金瓶梅

002,雜事秘辛

003,飛燕外傳

004,控鶴監(jiān)秘記

005,漢宮春色

求圖書管理系統(tǒng)(java)代碼?

java swing 登陸界面code

/*

* Login.java

*

* Created on __DATE__, __TIME__

*/

package com.agen.library.window;

import java.awt.Image;

import java.awt.Toolkit;

import javax.swing.JOptionPane;

import javax.swing.UIManager;

import javax.swing.UnsupportedLookAndFeelException;

import com.agen.library.factory.DAOFactory;

import com.agen.library.util.GlobalUser;

import com.agen.library.vo.User;

/**

*

* @author __USER__

*/

public class Login extends javax.swing.JFrame {

/**

*

*/

private static final long serialVersionUID = -2176093732040600809L;

/** Creates new form Login */

public Login() {

super("易云圖書管理軟件V1.0");

Image ime = Toolkit.getDefaultToolkit().getImage(

getClass().getResource("/images/ico.png"));

try {

UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());

} catch (ClassNotFoundException e) {

// TODO Auto-generated catch block

e.printStackTrace();

} catch (InstantiationException e) {

// TODO Auto-generated catch block

e.printStackTrace();

} catch (IllegalAccessException e) {

// TODO Auto-generated catch block

e.printStackTrace();

} catch (UnsupportedLookAndFeelException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

setIconImage(ime);

initComponents();

setLocationRelativeTo(null);

this.setResizable(false);

}

/**

* This method is called from within the constructor to initialize the form.

* WARNING: Do NOT modify this code. The content of this method is always

* regenerated by the Form Editor.

*/

// GEN-BEGIN:initComponents

// editor-fold defaultstate="collapsed" desc="Generated Code"

private void initComponents() {

jLabel2 = new javax.swing.JLabel();

jLabel3 = new javax.swing.JLabel();

jTextField1 = new javax.swing.JTextField();

jPasswordField1 = new javax.swing.JPasswordField();

jButton1 = new javax.swing.JButton();

jButton2 = new javax.swing.JButton();

jLabel1 = new javax.swing.JLabel();

jMenuBar1 = new javax.swing.JMenuBar();

jMenu1 = new javax.swing.JMenu();

jMenuItem1 = new javax.swing.JMenuItem();

jMenu2 = new javax.swing.JMenu();

jMenuItem2 = new javax.swing.JMenuItem();

setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

addKeyListener(new java.awt.event.KeyAdapter() {

public void keyPressed(java.awt.event.KeyEvent evt) {

formKeyPressed(evt);

}

public void keyTyped(java.awt.event.KeyEvent evt) {

formKeyTyped(evt);

}

});

jLabel2.setFont(new java.awt.Font("微軟雅黑", 0, 14));

jLabel2.setText("\u7528\u6237\u540d\uff1a");

jLabel3.setFont(new java.awt.Font("微軟雅黑", 0, 14));

jLabel3.setText("\u5bc6 \u7801\uff1a");

jTextField1.setFont(new java.awt.Font("微軟雅黑", 0, 14));

jTextField1.addActionListener(new java.awt.event.ActionListener() {

public void actionPerformed(java.awt.event.ActionEvent evt) {

jTextField1ActionPerformed(evt);

}

});

jPasswordField1.setFont(new java.awt.Font("微軟雅黑", 0, 12));

jPasswordField1.addKeyListener(new java.awt.event.KeyAdapter() {

public void keyTyped(java.awt.event.KeyEvent evt) {

jPasswordField1KeyTyped(evt);

}

});

jButton1.setBackground(new java.awt.Color(223, 216, 216));

jButton1.setFont(new java.awt.Font("微軟雅黑", 0, 14));

jButton1.setText("\u767b\u9646");

jButton1.addActionListener(new java.awt.event.ActionListener() {

public void actionPerformed(java.awt.event.ActionEvent evt) {

jButton1ActionPerformed(evt);

}

});

jButton2.setBackground(new java.awt.Color(223, 216, 216));

jButton2.setFont(new java.awt.Font("微軟雅黑", 0, 14));

jButton2.setText("\u53d6\u6d88");

jButton2.addActionListener(new java.awt.event.ActionListener() {

public void actionPerformed(java.awt.event.ActionEvent evt) {

jButton2ActionPerformed(evt);

}

});

jLabel1.setIcon(new javax.swing.ImageIcon(

getClass().getResource("/images/login_main.jpg"))); // NOI18N

jMenu1.setText("File");

jMenu1.setFont(new java.awt.Font("微軟雅黑", 0, 14));

jMenuItem1.setAccelerator(javax.swing.KeyStroke.getKeyStroke(

java.awt.event.KeyEvent.VK_Q,

java.awt.event.InputEvent.CTRL_MASK));

jMenuItem1.setText("Exit");

jMenuItem1.addMouseListener(new java.awt.event.MouseAdapter() {

public void mouseClicked(java.awt.event.MouseEvent evt) {

jMenuItem1MouseClicked(evt);

}

});

jMenuItem1.addActionListener(new java.awt.event.ActionListener() {

public void actionPerformed(java.awt.event.ActionEvent evt) {

jMenuItem1ActionPerformed(evt);

}

});

jMenu1.add(jMenuItem1);

jMenuBar1.add(jMenu1);

jMenu2.setText("Help");

jMenu2.setFont(new java.awt.Font("微軟雅黑", 0, 14));

jMenuItem2.setText("About");

jMenuItem2.addActionListener(new java.awt.event.ActionListener() {

public void actionPerformed(java.awt.event.ActionEvent evt) {

jMenuItem2ActionPerformed(evt);

}

});

jMenu2.add(jMenuItem2);

jMenuBar1.add(jMenu2);

setJMenuBar(jMenuBar1);

javax.swing.GroupLayout layout = new javax.swing.GroupLayout(

getContentPane());

getContentPane().setLayout(layout);

layout.setHorizontalGroup(layout

.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

.addComponent(jLabel1)

.addGroup(

layout.createSequentialGroup()

.addContainerGap()

.addGroup(

layout.createParallelGroup(

javax.swing.GroupLayout.Alignment.TRAILING,

false)

.addComponent(

jLabel2,

javax.swing.GroupLayout.Alignment.LEADING)

.addGroup(

javax.swing.GroupLayout.Alignment.LEADING,

layout.createSequentialGroup()

.addComponent(

jLabel3)

.addPreferredGap(

javax.swing.LayoutStyle.ComponentPlacement.RELATED)

.addGroup(

layout.createParallelGroup(

javax.swing.GroupLayout.Alignment.LEADING)

.addGroup(

layout.createSequentialGroup()

.addGap(10,

10,

10)

.addComponent(

jButton1)

.addGap(47,

47,

47)

.addComponent(

jButton2))

.addComponent(

jPasswordField1)

.addComponent(

jTextField1,

javax.swing.GroupLayout.DEFAULT_SIZE,

197,

Short.MAX_VALUE))

.addContainerGap()))));

layout.setVerticalGroup(layout

.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

.addGroup(

layout.createSequentialGroup()

.addComponent(jLabel1)

.addPreferredGap(

javax.swing.LayoutStyle.ComponentPlacement.RELATED)

.addGroup(

layout.createParallelGroup(

javax.swing.GroupLayout.Alignment.BASELINE)

.addComponent(jLabel2)

.addComponent(

jTextField1,

javax.swing.GroupLayout.PREFERRED_SIZE,

24,

javax.swing.GroupLayout.PREFERRED_SIZE))

.addPreferredGap(

javax.swing.LayoutStyle.ComponentPlacement.RELATED)

.addGroup(

layout.createParallelGroup(

javax.swing.GroupLayout.Alignment.BASELINE)

.addComponent(jLabel3)

.addComponent(

jPasswordField1,

javax.swing.GroupLayout.PREFERRED_SIZE,

23,

javax.swing.GroupLayout.PREFERRED_SIZE))

.addPreferredGap(

javax.swing.LayoutStyle.ComponentPlacement.RELATED)

.addGroup(

layout.createParallelGroup(

javax.swing.GroupLayout.Alignment.BASELINE)

.addComponent(jButton1)

.addComponent(jButton2))

.addContainerGap(

javax.swing.GroupLayout.DEFAULT_SIZE,

Short.MAX_VALUE)));

pack();

}// /editor-fold

// GEN-END:initComponents

private void jMenuItem2ActionPerformed(java.awt.event.ActionEvent evt) {

// TODO add your handling code here:

About.start();

}

private void jPasswordField1KeyTyped(java.awt.event.KeyEvent evt) {

if (evt.getKeyChar() == '\n') {

String name = jTextField1.getText(); // 獲取用戶名

String pass = String.valueOf(jPasswordField1.getPassword());// 獲取密碼

User user = null;

// 未輸入用戶名

if (name.equals("") || name == null) {

JOptionPane.showMessageDialog(this, "用戶名不允許為空!", "cuowu", 0);

return;

}

try {

user = DAOFactory.getIUserDAOInstance().findById(name);

if (user != null) {

if (user.getPass() != null user.getPass().equals(pass)) {

GlobalUser.LOGIN_USER = user; // 記錄當(dāng)前用戶

// 進(jìn)入主界面

Main.start();

this.dispose();

} else {

JOptionPane.showMessageDialog(this, "用戶名或密碼錯(cuò)誤!");

return;

}

}

} catch (Exception e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

if (user == null) {

JOptionPane.showMessageDialog(this, "用戶名或密碼錯(cuò)誤!", "消息", 0);

return;

}

}

}

private void formKeyTyped(java.awt.event.KeyEvent evt) {

}

private void formKeyPressed(java.awt.event.KeyEvent evt) {

}

private void jTextField1ActionPerformed(java.awt.event.ActionEvent evt) {

// TODO add your handling code here:

}

private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {

// TODO add your handling code here:

jTextField1.setText("");

jPasswordField1.setText("");

jTextField1.requestFocus();

}

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {

String name = jTextField1.getText(); // 獲取用戶名

String pass = String.valueOf(jPasswordField1.getPassword());// 獲取密碼

User user = null;

// 未輸入用戶名

if (name.equals("")) {

JOptionPane.showMessageDialog(this, "用戶名不允許為空!");

return;

}

try {

user = DAOFactory.getIUserDAOInstance().findById(name);

if (user != null) {

if (user.getPass() != null user.getPass().equals(pass)) {

GlobalUser.LOGIN_USER = user; // 記錄當(dāng)前用戶

// 進(jìn)入主界面

Main.start();

this.dispose();

} else {

JOptionPane.showMessageDialog(this, "用戶名或密碼錯(cuò)誤!", "消息", 0);

return;

}

}

} catch (Exception e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

if (user == null) {

JOptionPane.showMessageDialog(this, "用戶名或密碼錯(cuò)誤!", "消息", 0);

return;

}

}

private void jMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) {

if (JOptionPane.showConfirmDialog(this, "你確定要退出嗎?", "提示",

JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) {

System.exit(0);

}

}

private void jMenuItem1MouseClicked(java.awt.event.MouseEvent evt) {

System.exit(1);

}

/**

* @param args

* the command line arguments

*/

public static void main(String args[]) {

// System.out.println(Login.class.getResource("src/images/images/login_main.jpg"));

// new javax.swing.ImageIcon(

// Login.class.getResource("../../../../images/login_main.jpg"));

// new Login().setVisible(true);

java.awt.EventQueue.invokeLater(new Runnable() {

public void run() {

new Login().setVisible(true);

}

});

}

// GEN-BEGIN:variables

// Variables declaration - do not modify

private javax.swing.JButton jButton1;

private javax.swing.JButton jButton2;

private javax.swing.JLabel jLabel1;

private javax.swing.JLabel jLabel2;

private javax.swing.JLabel jLabel3;

private javax.swing.JMenu jMenu1;

private javax.swing.JMenu jMenu2;

private javax.swing.JMenuBar jMenuBar1;

private javax.swing.JMenuItem jMenuItem1;

private javax.swing.JMenuItem jMenuItem2;

private javax.swing.JPasswordField jPasswordField1;

private javax.swing.JTextField jTextField1;

// End of variables declaration//GEN-END:variables

}

java圖書館系統(tǒng)怎么看代碼看數(shù)據(jù)庫(kù)的信息

點(diǎn)擊電腦的開始。

首先點(diǎn)擊電腦的開始,找到QLServer配置管理器,將SQLServer網(wǎng)絡(luò)配置中的SQLEXPRESS的協(xié)議如下圖中的三個(gè)服務(wù)改為啟用,然后點(diǎn)擊TCPIP協(xié)議,修改動(dòng)態(tài)端口為1433,重啟服務(wù)器才能生效,首先建立一個(gè)java項(xiàng)目,命名為TestDB然后右鍵點(diǎn)擊TestDB選擇buildpath然后找到AddExternalJARs,找到下載的sqljdbc的包,打開即可,然后項(xiàng)目的referencedlibraries目錄下能看到導(dǎo)入的包,新建一個(gè)包database包中再建立TestConect執(zhí)行以下代碼,代碼執(zhí)行結(jié)果和數(shù)據(jù)庫(kù)中查詢的結(jié)果一樣。

當(dāng)前名稱:圖書查詢java代碼 查詢java圖書的詳細(xì)信息
URL網(wǎng)址:http://muchs.cn/article6/dojhhig.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供外貿(mào)建站、用戶體驗(yàn)移動(dòng)網(wǎng)站建設(shè)、服務(wù)器托管面包屑導(dǎo)航、網(wǎng)站建設(shè)

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)

成都網(wǎng)頁(yè)設(shè)計(jì)公司