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

📄 books.java

📁 实现图书管理
💻 JAVA
字号:
package mypkg;

import java.sql.*;
import java.text.*;

public class books extends Execute_DB
{
	//定义类成员变量
	private long BookID;    
	private String BookName;       
	private String Author;   
	private String Pub;
	private float Price;
	private String PicUrl;
	private long SortID;   
	private String Intro;
	private int RecommendNumber;
	private String strSql;
	
    
    //初始化类成员变量
	public books()
	{
		this.BookID=0;        
		this.BookName="";		
		this.Author="";		
		this.SortID=0;	
		this.Price=0;
		this.Pub="";
		this.PicUrl = "00000000000000.jpg";
		this.Intro = "";
		this.RecommendNumber = 0;
		this.strSql=""; 
	}
   
	//向books数据表中添加一条新记录
	public boolean add_book()
	{
        
		this.strSql="insert into books ";
		this.strSql=this.strSql + "(";        
		this.strSql=this.strSql + "BookName,";  
		this.strSql=this.strSql + "Author,";
		this.strSql=this.strSql + "Pub,";
		this.strSql=this.strSql + "Price,";
		this.strSql=this.strSql + "SortID,"; 
		this.strSql=this.strSql + "PicUrl,"; 
		this.strSql=this.strSql + "Intro,"; 
		this.strSql=this.strSql + "RecommendNumber";              
		this.strSql=this.strSql + ") ";        
		this.strSql=this.strSql + "values(";
		this.strSql=this.strSql + "'" + this.BookName + "',";	
		this.strSql=this.strSql + "'" + this.Author + "',";
		this.strSql=this.strSql + "'" + this.Pub + "',";
		this.strSql=this.strSql + "'" + this.Price + "',";
		this.strSql=this.strSql + "'" + this.SortID + "',";	
		this.strSql=this.strSql + "'" + this.PicUrl + "',";	
		this.strSql=this.strSql + "'" + this.Intro + "',";
		this.strSql=this.strSql + "'" + this.RecommendNumber + "'";
		this.strSql=this.strSql + ")";
		
		boolean isAdd = super.exeSql(this.strSql);		
		return isAdd;
	}   
   
  	//修改类成员变量BookID对应的图书信息
	public boolean modify_info()
	{
		this.strSql="update books set ";	
		this.strSql=this.strSql + "BookName=" + "'" + this.BookName + "',";
		this.strSql=this.strSql + "Author=" + "'" + this.Author + "',";		
		this.strSql=this.strSql + "Pub=" + "'" + this.Pub + "',";	
		this.strSql=this.strSql + "Price=" + "'" + this.Price + "',";	
		this.strSql=this.strSql + "SortID=" + "'" + this.SortID + "',";	
		this.strSql=this.strSql + "PicUrl=" + "'" + this.PicUrl + "',";
		this.strSql=this.strSql + "Intro=" + "'" + this.Intro + "'";	
		this.strSql=this.strSql + " where BookID=" + this.BookID;		
		
		boolean isUpdate = super.exeSql(this.strSql);		
		return isUpdate;
	}	
   
 	//删除类DeleteBookID中对应的图书信息
	public boolean delete_book(String DeleteBookID)
	{
		this.strSql="delete from books where BookID in (";
		this.strSql=this.strSql + DeleteBookID + ")";
		
		boolean isDelete = super.exeSql(this.strSql);		
		return isDelete;
	}
	////
	public boolean showform3()
	{	
		this.strSql="select * from formsendno ";             
		try
		{
			ResultSet rs = super.exeSqlQuery(this.strSql);
			if (rs.next())
			{
			this.BookName=rs.getString("BookName");
			this.Author=rs.getString("Author");
			this.Pub=rs.getString("pub");
			this.Price=rs.getFloat("Price");
			return true;
		}
		else
		{
			return false;			
		} 
	}
	catch(Exception ex)
	{		 
		return false;
	}
}
   
	//获取类成员变量BookID对应的图书信息
	public boolean  init()
	{
		this.strSql="select * from books where BookID=";
		this.strSql=this.strSql + this.BookID;        
		System.out.println(strSql);      
		try
		{
			ResultSet rs = super.exeSqlQuery(this.strSql);
			if (rs.next())
			{
				this.BookID=rs.getLong("BookID");                
				this.BookName=rs.getString("BookName"); 
				this.Pub=rs.getString("Pub");
				this.Author=rs.getString("Author");
				this.PicUrl=rs.getString("PicUrl");   
				this.Price=rs.getFloat("Price");
				this.SortID=rs.getInt("SortID");   
				this.Intro=rs.getString("Intro");
				this.RecommendNumber=rs.getInt("RecommendNumber");
				return true;
			}
			else
			{
				return false;			
			} 
		}
		catch(Exception ex)
		{		 
			return false;
		}
	}
	
	//获取所有普通图书信息,返回一个ResultSet类型对象
	public ResultSet show_books()
	{
		this.strSql="select * from books";
		ResultSet rs = null;              
		try
		{
			rs = super.exeSqlQuery(this.strSql); 
		}
		catch(Exception ex)
		{
			System.out.println(ex.toString());            
		}
		return rs;        
	} 
	
	//获得按RecommendNumber排序的图书集合,返回一个ResultSet类型对象
	public ResultSet show_books_ByRecommendNumber()
	{
		this.strSql="select * from books order by RecommendNumber desc";
		ResultSet rs = null;              
		try
		{
			rs = super.exeSqlQuery(this.strSql); 
		}
		catch(Exception ex)
		{
			System.out.println(ex.toString());            
		}
		return rs;        
	} 
   
   	//以BookName、Author、Pub、SortID为条件搜索books数据表,获得符合条件的记录,返回一个ResultSet类型对象
	public ResultSet search_books(String BookName,String Author,String Pub,long SortID)
	{
		this.strSql="select * from books where";
		this.strSql=this.strSql + " BookName like '%" + BookName +"%'";    
		this.strSql=this.strSql + " and Author like '%" + Author +"%'"; 
		this.strSql=this.strSql + " and Pub like '%" + Pub +"%'";
		if(SortID != 0)
		{
			this.strSql=this.strSql + " and SortID =" + SortID;		
		}
		
		ResultSet rs = null;              
		try
		{
			rs = super.exeSqlQuery(this.strSql); 
		}
		catch(Exception ex)
		{
			System.out.println(ex.toString());            
		}
		return rs;        
	} 

	//更改类成员变量BookID对应的记录中RecommendNumber的值
	public boolean modify_RecommendNumber()
	{
		this.strSql="update books set ";
		this.strSql=this.strSql + "RecommendNumber=" + "'" + this.RecommendNumber + "'";
		this.strSql=this.strSql + " where BookID =" + this.BookID;
		
		boolean isUpdate = super.exeSql(this.strSql);		
		return isUpdate;
	}
   
	//设置类成员变量BookID的值 
	public void setBookID(long BookID)
	{
		this.BookID = BookID;	
	}   

	//获取类成员变量BookID的值  
	public long getBookID()
	{
		return this.BookID;	
	} 
	
	 //设置类成员变量BookName的值 
 	public void setBookName(String BookName)
	{
		this.BookName = BookName;	
	}   

	//获取类成员变量BookName的值  
	public String getBookName()
	{
		return this.BookName;	
	} 
	
	 //设置类成员变量Author的值 
 	public void setAuthor(String Author)
	{
		this.Author = Author;	
	}   

	//获取类成员变量Author的值  
	public String getAuthor()
	{
		return this.Author;	
	} 
	
	 //设置类成员变量Pub的值 
 	public void setPub(String Pub)
	{
		this.Pub = Pub;	
	}   

	//获取类成员变量Pub的值  
	public String getPub()
	{
		return this.Pub;	
	} 
	
	//设置类成员变量Price的值 
 	public void setPrice(float Price)
	{
		this.Price = Price;	
	}   

	//获取类成员变量Price的值  
	public float getPrice()
	{
		return this.Price;	
	} 
	
	 //设置类成员变量SortID的值 
 	public void setSortID(long SortID)
	{
		this.SortID = SortID;	
	}   

	//获取类成员变量SortID的值  
	public long getSortID()
	{
		return this.SortID;	
	}
	 	
	//设置类成员变量PicUrl的值 
 	public void setPicUrl(String PicUrl)
	{
		this.PicUrl = PicUrl;	
	}   

	//获取类成员变量PicUrl的值  
	public String getPicUrl()
	{
		return this.PicUrl;	
	} 
	
	//设置类成员变量Intro的值 
 	public void setIntro(String Intro)
	{
		this.Intro = Intro;	
	}   

	//获取类成员变量Intro的值  
	public String getIntro()
	{
		return this.Intro;	
	} 
	
	//设置类成员变量RecommendNumber的值 
 	public void setRecommendNumber(int RecommendNumber)
	{
		this.RecommendNumber = RecommendNumber;	
	}   

	//获取类成员变量RecommendNumber的值  
	public int getRecommendNumber()
	{
		return this.RecommendNumber;	
	} 
}

⌨️ 快捷键说明

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