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

📄 bookdbdao.java

📁 网上书店 源代码和数据库网上书店 源代码和数据库
💻 JAVA
字号:
package com.shop.model.dao.addbook;

import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Statement;

import com.shop.model.utils.DataBaseConn;

public class BookdbDAO {
	public void updateDB(String id,int buyCount) {
		Connection conn = null;
		Statement st = null;

		DataBaseConn dataBaseConn = new DataBaseConn();
		conn = dataBaseConn.getConnection();
		try {
			st = conn.createStatement();
			
				String sql = "update bookinfo set remainnumber=remainnumber-"+buyCount+ "where isbn='"
						+ id+"'";
				st.execute(sql);

			
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally{
			if(st!=null){
				try {
					st.close();
				} catch (SQLException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
			if(conn!=null){
				try {
					conn.close();
				} catch (SQLException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
				
			}
			
			
		}

	}
	public void removeBook(String[] ids){

		Connection conn = null;
		Statement st = null;

		DataBaseConn dataBaseConn = new DataBaseConn();
		conn = dataBaseConn.getConnection();
		try {
			st = conn.createStatement();
			for (String id : ids) {
				String sql = "update bookinfo set remainnumber=remainnumber+1 where isbn='"
						+ id+"'";
				st.execute(sql);

			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally{
			if(st!=null){
				try {
					st.close();
				} catch (SQLException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
			if(conn!=null){
				try {
					conn.close();
				} catch (SQLException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
				
			}
			
			
		}

	
     		
		
		
		
	}
	
	
	
	
	
	
	
	
	
	
	
	public void addBookCount(String isbn,int num){

		Connection conn = null;
		Statement st = null;

		DataBaseConn dataBaseConn = new DataBaseConn();
		conn = dataBaseConn.getConnection();
		try {
			st = conn.createStatement();
			String sql = "update bookinfo set remainnumber=remainnumber+"+num+" where isbn='"
						+ isbn+"'";
				st.execute(sql);

			
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally{
			if(st!=null){
				try {
					st.close();
				} catch (SQLException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
			if(conn!=null){
				try {
					conn.close();
				} catch (SQLException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
				
			}
			
			
		}

	
     		
		
		
		
	}

}

⌨️ 快捷键说明

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