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

📄 bookinformationd.java

📁 实现在线的增删改查和一些基本的功能!这是一个简单的网页!
💻 JAVA
字号:
package Dao;
import java.util.List;
import java.util.ArrayList;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import model.BookInformation;

import Util.DBHelper;

public class BookInformationD {
	private Connection conn;
	private PreparedStatement ps;
	private ResultSet rs;
	//获得所有的图书信息
	public List getAllInformation(){
		List list=new ArrayList();
		Connection conn=DBHelper.getCon();
		String sql="select*from BookInformation";
		try {
			ps=conn.prepareStatement(sql);
			rs=ps.executeQuery();
			while(rs.next()){
				BookInformation book=new BookInformation();
				book.setAutor(rs.getString("autor"));
				book.setBookid(rs.getInt("bookid"));
				book.setBookidentifiler(rs.getString("bookidentifiler"));
				book.setExitprice(rs.getDouble("exitprice"));
				//book.setImportprice(rs.getDouble("importprice"));
				//book.setPicturename(rs.getString("picture"));
				book.setPublishDate(rs.getDate("publishdate"));
				book.setPublishid(rs.getInt("publishid"));
				book.setPublishname(rs.getString("publishname"));
				book.setSortid(rs.getInt("sortid"));
				book.setSortpublish(rs.getString("sortpublish"));
				list.add(book);
				
			}
		} catch (SQLException e) {
			
			e.printStackTrace();
		}
		return list;
		
	  
	}
	//根据图书编号获得一本书的信息
	public BookInformation getBookId(int Bookid){
		BookInformation book=null;
		Connection conn=DBHelper.getCon();
		String sql="select*from BookInformation where Bookid=?";
		try {
			ps=conn.prepareStatement(sql);
			ps.setInt(1, Bookid);
			rs=ps.executeQuery();
			while(rs.next()){
				book =new BookInformation();
				book.setAutor(rs.getString("autor"));
				book.setBookid(rs.getInt("bookid"));
				book.setBookidentifiler(rs.getString("bookidentifiler"));
				book.setExitprice(rs.getDouble("exitprice"));
				//book.setImportprice(rs.getDouble("importprice"));
				//book.setPicturename(rs.getString("picture"));
				book.setPublishDate(rs.getDate("publishdate"));
				book.setPublishid(rs.getInt("publishid"));
				book.setPublishname(rs.getString("publishname"));
				book.setSortid(rs.getInt("sortid"));
				book.setSortpublish(rs.getString("sortpublish"));
			}
		} catch (SQLException e) {
			
			e.printStackTrace();
		}
		return book;
		
	}
	/***
	 * 获取书籍的数量
	 * ***/
	public int getCount(){
		int count=0;
		String sql="select count(*) from BookInformation";
		try {
			ps=conn.prepareStatement(sql);
			rs=ps.executeQuery();
			if(rs.next()){
				count=rs.getInt(1);
			}
		} catch (SQLException e) {
			
			e.printStackTrace();
		}
		
		
		return count;
		
	}
	public List getBookPage(int currentPage ,int pageSize){
		List list=new ArrayList();
		String sql = "select top " +pageSize+" * from BookInformation where bookid not in (select top " +(currentPage - 1)*pageSize +" bookid from book)";
		System.out.println(sql);
		try {
			ps=conn.prepareStatement(sql);
			rs=ps.executeQuery();
			while(rs.next()){
				BookInformation bookinfo=new BookInformation();
				bookinfo.setAutor(rs.getString("Autor"));
				bookinfo.setBookid(rs.getInt("Bookid"));
				bookinfo.setBookidentifiler(rs.getString("Bookidentifiler"));
				bookinfo.setExitprice(rs.getDouble("Exitprice"));
				bookinfo.setImportprice(rs.getDouble("Importprice"));
				bookinfo.setPicturename(rs.getString("Picturename"));
				bookinfo.setPublishDate(rs.getDate("PublishDate"));
				bookinfo.setPublishid(rs.getInt("Publishid"));
				bookinfo.setPublishname(rs.getString(""));
				bookinfo.setSortid(rs.getInt("Publishname"));
				bookinfo.setSortpublish(rs.getString("Sortid"));
				list.add(bookinfo);
				
			}
		} catch (SQLException e) {
			
			e.printStackTrace();
		}
		return list;
	}
	public Connection getCon(){
		return conn;
		
	}
	public void setConn(Connection conn){
		this.conn=conn;
	}

}

⌨️ 快捷键说明

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