downloadcommentado.java

来自「辅助办公系统,具有发布公告、站内邮箱、日程安排、日志查看等功能」· Java 代码 · 共 94 行

JAVA
94
字号
package com.x3408.download;

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

import com.x3408.database.CNProvider;

public class DownLoadCommentADO {

	public static boolean commentInsert(CommentInfo commentInfo){
		Connection conn=CNProvider.getConnection();
		PreparedStatement pstat=null;
		if(commentInfo.isValid()){
			try {
				pstat=conn.prepareStatement("insert downLoadComment(fileID,comment,commenter,commentPubTime)values(?,?,?,?)");
				pstat.setInt(1, commentInfo.getFileID());
				pstat.setString(2, commentInfo.getComment());
				pstat.setString(3, commentInfo.getCommenter());
				pstat.setString(4, commentInfo.getCommentPubTime());
				pstat.executeUpdate();
				return true;
			} catch (SQLException e) {
				// TODO 自动生成 catch 块
				e.printStackTrace();
			}
		}
		return false;
	}
	public static boolean commentDelete(String fieldName,String pFieldValue){
		Connection conn=CNProvider.getConnection();
		PreparedStatement pstat=null;
		if(pFieldValue!=null&&!"".equals(pFieldValue.trim())){
			int fieldValue=Integer.parseInt(pFieldValue.trim());
			try {
				pstat=conn.prepareStatement("delete from downLoadComment where "+fieldName+"=?");
				pstat.setInt(1, fieldValue);
				pstat.executeUpdate();
				return true;
			} catch (SQLException e) {
				// TODO 自动生成 catch 块
				e.printStackTrace();
			}
		}
		return false;
	}

	public static Vector allCommentQuery(String pFileID){
		Connection conn=CNProvider.getConnection();
		ResultSet rs=null;
		PreparedStatement pstat=null;
		Vector<CommentInfo> commentList=new Vector<CommentInfo>();
		CommentInfo commentInfo=null;
		int fileID=Integer.parseInt(pFileID);
		try {
			pstat=conn.prepareStatement("select * from downLoadComment where fileID=?");
			pstat.setInt(1, fileID);
			rs=pstat.executeQuery();
			while(rs.next()){
				commentInfo=new CommentInfo(rs.getString("commentID"),rs.getString("fileID"),
						rs.getString("comment"),rs.getString("commenter"),rs.getString("commentPubTime"));
				commentList.addElement(commentInfo);
			}
			return commentList.size()<1?null:commentList;
		} catch (SQLException e) {
			// TODO 自动生成 catch 块
			e.printStackTrace();
		}
		return null;
	}
	public static CommentInfo commentQuery(String pCommentID){
		Connection conn=CNProvider.getConnection();
		PreparedStatement pstat=null;
		ResultSet rs=null;
		CommentInfo commentInfo=null;
		int commentID=Integer.parseInt(pCommentID);
		try {
			pstat=conn.prepareStatement("select * from downLoadComment where commentID=?");
			pstat.setInt(1, commentID);
			rs=pstat.executeQuery();
			if(rs.next()){
				commentInfo=new CommentInfo(rs.getString("commentID"),rs.getString("fileID"),
						rs.getString("comment"),rs.getString("commenter"),rs.getString("commentPubTime"));
			}
		} catch (SQLException e) {
			// TODO 自动生成 catch 块
			e.printStackTrace();
		}
		return commentInfo;
	}
}

⌨️ 快捷键说明

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