⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 books.java

📁 图书馆管理系统,从我们导师的实验室(国家重点实验室)带出来的,不过是我们自己开发的,已经提交,没有问题!站长采纳,可别说是偶传的噢!
💻 JAVA
字号:
package booksys;


import java.sql.*;
import java.io.*;
import java.util.*;

/**书籍类*/
public class books{
	int bookid;
	String booknm;
	String author1;
	String author2;
	String isbn;
	float price;
	int publisherid;
	//int publisherid2;
	String version;
	String introduce;
	boolean newbook;
	static BufferedReader in;
	static books book1;
	static bookstores bookstores1;
	public static Vector bookv=new Vector();
	
	public books(){
		
		}
	
	public books(int bookid,String booknm,String author1,String author2,String isbn,
				 float price,int publisherid,String version,String introduce){
				 	
				 	this.bookid = bookid;
				 	this.booknm = booknm;
				 	this.author1 = author1;
				 	this.author2 = author2;
				 	this.isbn = isbn;
				 	this.price = price;
				 	this.publisherid = publisherid;				 	
				 	this.version = version;
				 	this.introduce = introduce;
				 	}
				 	
	public static int getid() throws Exception{
		int count = 0;
		dbconn.conn();
		String sql = "select * from books";
		ResultSet rs=dbconn.dbquery(sql);
		while(rs.next()){
			count=rs.getInt(1);			
			}
		return count+1;
		}
	
	public int getbookid(){
		return bookid;
		}
		
	public String getnm(){
		return booknm;
		}
		
	public String getauthor1(){
		return author1;
		}
		
	public String getauthor2(){
		return author2;
		}
		
	public String getisbn(){
		return isbn;
		}
		
	public float getprice(){
		return price;
		}
		
	public int getpublisherid(){
		return publisherid;
		}
		
	public String getversion(){
		return version;
		}
	
	public String getintroduce(){
		return introduce;
		}
	
	public String toString(){
		return new String("\n\n书籍id: "+ Integer.toString(bookid).trim()+
						  "\t书名: "+ booknm.trim() +"\t作者1: "+author1.trim()+
						  "\t作者2: "+author2.trim()+"\t书ISBN: "+isbn.trim()+"\t单价: "+Float.toString(price).trim()+
						  "\t出版社1id: "+Integer.toString(publisherid).trim()+
	    				  "\t版本: "+version.trim()+"\t书简介: "+introduce.trim());
		}
		
			
	public static Vector browse(String sql) throws Exception{
		books book;
		bookv.clear();
		dbconn.conn();
		//String s = "select * from books order by bookid";
		ResultSet rs=dbconn.dbquery(sql);
		
		while(rs.next()){	
		/*	bookid = rs.getInt(1);
			booknm = rs.getString(2);
			author1 = rs.getString(3);
			author2 = rs.getString(4);
			isbn = rs.getString(5);
			price = rs.getFloat(6);
			publisherid1 = rs.getInt(7);
			publisherid2 = rs.getInt(8);
			version = rs.getString(8);
			introduce = rs.getString(9);*/
			
		    book = new books(rs.getInt(1),rs.getString(2),rs.getString(3),rs.getString(4),rs.getString(5),rs.getFloat(6),rs.getInt(7),rs.getString(8),rs.getString(9));
			bookv.addElement(book);		 		   		
			}
		
		dbconn.dbclose();
		return bookv;
		}
	
	/**按书名查找,在读者查询书时使用*/	
	/*public void browse(String booknm) throws Exception{
		books book;
		dbconn.conn();
		String s = "select * from books where booknm ='"+booknm+"'";
		ResultSet rs=dbconn.dbquery(s);
		
		while(rs.next()){	
			bookid = rs.getInt(1);
			booknm = rs.getString(2);
			author1 = rs.getString(3);
			author2 = rs.getString(4);
			isbn = rs.getString(5);
			price = rs.getFloat(6);
			publisherid = rs.getInt(7);
			version = rs.getString(8);
			introduce = rs.getString(9);
			
		    book = new books(bookid,booknm,author1,author2,isbn,price,publisherid,version,introduce);
					 
		    System.out.println("\n"+book);			
			}
		dbconn.dbclose();
		}*/
	
	/**按作者和书名查找,在读者查询书时使用*/	
	public void browse(String booknm,String author) throws Exception{
		books book;
		dbconn.conn();
		String s = "select * from books where booknm='"+booknm+"' and author1='"+author+"'";
		ResultSet rs=dbconn.dbquery(s);
		
		while(rs.next()){	
			bookid = rs.getInt(1);
			booknm = rs.getString(2);
			author1 = rs.getString(3);
			author2 = rs.getString(4);
			isbn = rs.getString(5);
			price = rs.getFloat(6);
			publisherid = rs.getInt(7);			
			version = rs.getString(8);
			introduce = rs.getString(9);
			
		    book = new books(bookid,booknm,author1,author2,isbn,price,publisherid,version,introduce);
					 
		    System.out.println("\n"+book);			
			}
		dbconn.dbclose();
		}
		
	/**按出版社和书名查找,在读者查询书时使用*/	
	public void browse(String booknm,int publisherid) throws Exception{
		books book;		
		dbconn.conn();
		String s = "select * from books where booknm='"+booknm+"' and publisherid="+publisherid;
		ResultSet rs=dbconn.dbquery(s);
		
		while(rs.next()){	
			bookid = rs.getInt(1);
			booknm = rs.getString(2);
			author1 = rs.getString(3);
			author2 = rs.getString(4);
			isbn = rs.getString(5);
			price = rs.getFloat(6);
			publisherid = rs.getInt(7);
		
			version = rs.getString(8);
			introduce = rs.getString(9);
			
		    book = new books(bookid,booknm,author1,author2,isbn,price,publisherid,version,introduce);
					 
		    System.out.println("\n"+book);			
			}
		dbconn.dbclose();
		}
	
	/**增加新书	*/
	public boolean addnewbook() throws Exception{
		boolean result = false;
		dbconn.conn();
		String sql = "insert into books values("+bookid+",'"+booknm+"','"+author1+"','"+author2+"','"+isbn+"',"+price+","+publisherid+",'"+version+"','"+introduce+"')";
		int count=dbconn.dbinsert(sql);
		dbconn.conn();
		if(count>0) result=true;
		return result;
		}
		
		/**按书id查询书名,被读者类查询借书情况时使用。*/
	public static String searchbook(int bookid) throws Exception{
		dbconn.conn();
		String sql = "select booknm from books where bookid ="+bookid;
		ResultSet rs = dbconn.dbquery(sql);
		if(rs.next()) return rs.getString(1);
		else return "";
		}
	
	/**检查书是否存在
	   如果存在,更新书数量。
	   如果不存在,更新书信息及数量*/	
	public static Vector checknewbook(String booknm) throws Exception{
		dbconn.conn();
		bookv.clear();
		String sql = "select * from books where booknm='"+booknm+"'";
		ResultSet rs=dbconn.dbquery(sql);		
		while(rs.next()){			
			books b1= new books(rs.getInt(1),rs.getString(2).trim(),rs.getString(3).trim(),rs.getString(4).trim(),rs.getString(5).trim(),rs.getFloat(6),rs.getInt(7),rs.getString(8).trim(),rs.getString(9).trim());									
			bookv.addElement(b1);			
		}
		return bookv;
	}
		
	public static books selectbook(int bookid) throws Exception{
		return book1;
		}
		

	
	}
		

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -