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

📄 updownoper.java

📁 某高校的门户网站源码
💻 JAVA
字号:
package com.zzx.updownload;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import com.zzx.util.DataConn;

public class UpDownOper {
     
	private Connection conn = null;
	private PreparedStatement psmt= null;
	
	public void insert(UpFile upfile){
		String sql = "insert into updown(filename,filecontent)values(?,?)";
	
		try{
			conn= new DataConn().getConn();
			psmt = conn.prepareStatement(sql);
			psmt.setString(1, upfile.getFilename());
			psmt.setString(2, upfile.getFilecontent());
			psmt.executeUpdate();
			psmt.close();
		}catch(Exception e){
			e.printStackTrace();
		}finally{
			try {
				conn.close();
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
	
	}
	
	public List<UpFile> queryAll(){
		
		String sql= "select * from updown";
		List<UpFile> all = new ArrayList();
		ResultSet rs =null;
		try{
			conn= new DataConn().getConn();
			psmt = conn.prepareStatement(sql);		
            rs = psmt.executeQuery();

             while(rs.next()){
            	 UpFile upfile = new UpFile();
            	 upfile.setId(rs.getInt(1));
            	 upfile.setFilename(rs.getString(2));
            	 upfile.setFilecontent(rs.getString(3));
            	 all.add(upfile);
             }
             rs.close();
			psmt.close();
		}catch(Exception e){
			e.printStackTrace();
		}finally{
			try {
				conn.close();
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
		return all;
	
	}
	
  public List<UpPic> queryAll(int currentPage,int lineSize){
		
	    String sql = "SELECT * FROM updown order by id desc limit "+ (currentPage - 1) * lineSize + "," + lineSize;
		List<UpPic> all = new ArrayList();
		ResultSet rs =null;
		try{
			conn= new DataConn().getConn();
			psmt = conn.prepareStatement(sql);		
            rs = psmt.executeQuery();

             while(rs.next()){
            	 UpPic uppic = new UpPic();
            	 uppic.setId(rs.getInt(1));
            	 uppic.setFilename(rs.getString(2));
            	 uppic.setFilecontent(rs.getString(3));
            	 all.add(uppic);
             }
            rs.close();
			psmt.close();
		}catch(Exception e){
			e.printStackTrace();
		}finally{
			try {
				conn.close();
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
		return all;
	
	}
	
	  public  void delete(int id){
	    	 Connection conn = new DataConn().getConn();
			 PreparedStatement psmt = null;
			 String sql = "delete from updown where id=?";			 
			 try {
					psmt = conn.prepareStatement(sql);
					psmt.setInt(1, id);
					psmt.executeUpdate();
					psmt.close();
				} catch (SQLException e) {
					e.printStackTrace();
				}finally{
					try {
						conn.close();
					} catch (SQLException e) {
						e.printStackTrace();
					}
				}			 
	    }
	  
	  public  int queryCount(){
	    	 int count=0;
		     Connection conn = new DataConn().getConn();
			 PreparedStatement psmt = null;
			 ResultSet rs = null;
			 String sql = "SELECT count(*) FROM updown ";			 
			 try {
				 psmt = conn.prepareStatement(sql);
				 rs = psmt.executeQuery();
				 while(rs.next()){
					 count = rs.getInt(1);
				 }
			} catch (SQLException e) {
				e.printStackTrace();
			}finally{
				try {
					conn.close();
				} catch (SQLException e) {
					e.printStackTrace();
				}
			}						
		 return count;
	  }
	
}

⌨️ 快捷键说明

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