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

📄 librarydaoipml.java

📁 一个简单的图书馆的管理系统,该系统主要是针对学校的图书馆而做的
💻 JAVA
字号:
package librarymanagement.dao.libraryDao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Vector;

import javax.swing.JOptionPane;





import librarymanagement.dao.common.DBConnectionManager;
import librarymanagement.dao.common.DbException;
import librarymanagement.dao.common.DbSql;
import librarymanagement.view.dialog.BookMangement;
import librarymanagement.vo.BookVo;

public class LibraryDaoIpml implements LibraryDao {
	
/**
  *按图书编号、存放位置、作者、图书名精确查找
 */
	public Vector findBookByAuthor(String author) throws DbException {
		
		return buildConnectionSQL(DbSql.MANAGER_SELECT_ALLBook  +  DbSql.WHERE  + DbSql.By_AUTHOR1 ,author);
	  }
	
	public Vector findBookByBook_name(String book_name) throws DbException {
	  	 return  buildConnectionSQL(DbSql.MANAGER_SELECT_ALLBook  +  DbSql.WHERE  + DbSql.By_BOOK_NAME1 ,book_name);
	    }
    public Vector findBookByLocation(String book_location) throws DbException {
		return  buildConnectionSQL(DbSql.MANAGER_SELECT_ALLBook  +  DbSql.WHERE  + DbSql.By_BOOK_LOCATION1 ,book_location);
		 }
    public Vector findBookBybook_id(int book_id) throws DbException {
    	DBConnectionManager manager = DBConnectionManager.getInstance();
		 Connection con = null;
		 PreparedStatement pstmt = null;
		 ResultSet set = null;
		 Vector v=null;
		
		 try {
		      con = manager.getConnection("oracle");
		      pstmt = con.prepareStatement(DbSql.MANAGER_SELECT_ALLBook  +  DbSql.WHERE  + DbSql.By_BOOK_ID1);
		      pstmt.setLong(1, book_id);
		      System.out.println(book_id);
		      set = pstmt.executeQuery();
		      v = new Vector();
		      resetVector( set,  v);
		      if (v.size() == 0) {
		        throw new DbException("数据库中不存在符合条件的记录,请重新输入");
		      }
		    } catch (SQLException e) {
		      System.out.println("查找书籍信息dao异常: " + e.getMessage());
		    } finally {
		      manager.freeConnection("oracle", con);
		    }
		    return v;
		   }
/**
 * 按图书编号、存放位置、作者、图书名模糊查找
 */
/**
 * Daoipml中删除所选记录
 */
	public boolean deleteBookById(int book_id) {
		DBConnectionManager manager = DBConnectionManager.getInstance();
		 Connection con = null;
		 PreparedStatement pstmt = null;
	     boolean flag = false;
		  try {
		      con = manager.getConnection("oracle");
		      pstmt = con.prepareStatement(DbSql.DELETEBy_BOOK_ID);
		      pstmt.setLong(1, book_id);
		      int count = pstmt.executeUpdate();
		      if(count != 0){
		        flag = true;
		      }
		    }catch(SQLException e){
		      System.out.println("信息删除dao异常:= " + e.getMessage());
		    }
		    return flag;
		   }
/**
 * 刷新的后台处理
 */
	public Vector findBookInfo() throws DbException {
		
		DBConnectionManager manager = DBConnectionManager.getInstance();
		 Connection con = null;
		 PreparedStatement pstmt = null;
		 ResultSet set = null;
		 Vector v=null;
		
		 try {
		      con = manager.getConnection("oracle");
		      pstmt = con.prepareStatement(DbSql. MANAGER_SELECT_ALLBook);
		      set = pstmt.executeQuery();
		      v = new Vector();
		      resetVector( set,  v);
		      if (v.size() == 0) {
		        throw new DbException("数据库中不存在符合条件的记录,请重新输入");
		      }
		    } catch (SQLException e) {
		      System.out.println("查找书籍信息dao异常: " + e.getMessage());
		    } finally {
		      manager.freeConnection("oracle", con);
		    }
		    return v;
	}

	
	 
	  /**
	   * 根据传入查找条件的不同,
	   * 而来获得一个Vector对象的共同方法
	   * @param sql
	   * @param name
	   * @return
	   * @throws DbException
	   */
	  public Vector buildConnectionSQL(String sql,String name) throws DbException{
			DBConnectionManager manager = DBConnectionManager.getInstance();
			 Connection con = null;
			 PreparedStatement pstmt = null;
			 ResultSet set = null;
			 Vector v=null;
			// Statement stmt=null;
			
			 try {
			      con = manager.getConnection("oracle");
			   //   stmt=con.createStatement();
			      pstmt = con.prepareStatement(sql);
			      pstmt.setString(1, name);
			    set = pstmt.executeQuery();
			    //  set = stmt.executeQuery(sql);
			      v = new Vector();
			      resetVector( set,  v);
			      System.out.println("运行到此size    "+v.size());
			       if (v.size() == 0) {
			        throw new DbException("数据库中不存在符合条件的记录,请重新输入");
			      }
			    } catch (SQLException e) {
			      System.out.println("根据书名查找书籍信息dao异常: " + e.getMessage());
			    } finally {
			      manager.freeConnection("oracle", con);
			    }
			    return v;
		}
/**
 * 增加图书的后台处理
 * @throws SQLException 
 */
	public boolean AddbookInfo(BookVo value)  {
		DBConnectionManager manager = DBConnectionManager.getInstance();
		 boolean flag=false;
		 Connection con = null;
		 PreparedStatement pstmt = null;
		
			 con = manager.getConnection("oracle");
			
			try {
				System.out.println(value.getBook_id()+value.getBook_Name()+value.getKind()
						+value.getAuthor()+value.getPublis_com()+value.getBook_location()+value.getBook_amount()
						+value.getPrice()+value.getEdition()+value.getIn_amount());
				pstmt=con.prepareStatement(DbSql.INSERT_INFO);
				pstmt.setInt(1,value.getBook_id());
				pstmt.setString(2,value.getBook_Name());
				pstmt.setString(3,value.getKind());
				pstmt.setString(4,value.getAuthor());
				pstmt.setString(5,value.getEdition());
				pstmt.setString(6,value.getPublis_com());
				pstmt.setString(7,value.getBook_location());
				pstmt.setInt(8,value.getBook_amount());
				pstmt.setDouble(9,value.getPrice());
				pstmt.setInt(10,value.getIn_amount());
			    int count = pstmt.executeUpdate();

			    if(count!=0){
			    	flag=true;
			    }
			
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}

		 return flag;
	}
	 public boolean UpdatebookInfo(BookVo value) throws SQLException {
		 DBConnectionManager manager = DBConnectionManager.getInstance();
		    boolean flag = false;
		    PreparedStatement pstmt = null;
		    Connection con = null;
		    ResultSet set = null;
		  
		      con = manager.getConnection("oracle");
		      pstmt = con.prepareStatement(DbSql.UPDATE_EMPLOYEE_BY_ID);
		      //pstmt.setInt(11,value.getBook_id());
		      //  pstmt.setInt(1,value.getBook_id());
				pstmt.setString(1,value.getBook_Name());
				pstmt.setString(2,value.getKind());
				pstmt.setString(3,value.getAuthor());
				pstmt.setString(4,value.getPublis_com());
				pstmt.setString(5,value.getBook_location());
				pstmt.setInt(6,value.getBook_amount());
				pstmt.setDouble(7,value.getPrice());
				pstmt.setString(8,value.getEdition());
				pstmt.setInt(9,value.getIn_amount());
				 pstmt.setInt(10,value.getBook_id());
			    int count = pstmt.executeUpdate();
			   
		      if(count != 0){
		        flag = true;
		      }
		 
		    return flag;
		  }
	 /**
	  * 向动态数组中加入BookVo对象
	  * @param set
	  * @param v
	  * @return v
	  * @throws SQLException
	  */
	 public Vector resetVector(ResultSet set, Vector v) throws SQLException {
		  while (set.next()) {
				
			  int book_id = set.getInt("book_id");
			  String book_Name = set.getString("book_Name");
			  String kind = set.getString("kind");
			  String author = set.getString("author");
			  
			  String publis_com = set.getString("publis_com");
			  String book_location = set.getString("book_location");
			  int book_amount = set.getInt("book_amount");
			  double price = set.getDouble("price");
			  
			  String edition = set.getString("edition");
			  int in_amount = set.getInt("in_amount");
			 
			  v.addElement(new BookVo(book_id, book_Name, kind, author, publis_com,
					  book_location, book_amount, price, edition,in_amount));
			}
		
	    return v;
	  }

}

⌨️ 快捷键说明

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