secondleveltitledboperation.java

来自「新闻发布系统」· Java 代码 · 共 75 行

JAVA
75
字号
package DBOperation;

import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.*;
import JavaBean.SecondLevelTitle;

public class SecondLevelTitleDbOperation {

	DBConnection db;
	public SecondLevelTitleDbOperation()
	{
		db = new DBConnection("news");
	}

	/**
	 * 添加二级标题
	 */
	public boolean insertSecondLevelTitle(SecondLevelTitle title)
	{
		
		String sql = "insert into SecondLevelTitle values(?,?,?,?,?)";
		try {
			db.getCon();
			db.preSta = db.con.prepareStatement(sql);
			db.preSta.setString(1, title.getTitleName());
			db.preSta.setString(2, title.getFilePath());
			db.preSta.setString(3, title.getCreater());
			db.preSta.setString(4, title.getCreatTime());
			db.preSta.setLong(5, title.getParentTitle());
			return !(db.preSta.execute());
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return false;
		}
	}

	/**
	 * 按一标题查找所有的二级标题f
	 * @param parentTitleId
	 * @return
	 */
	public ArrayList findSeondLevelTitleOnFirstLevelTitle(int parentTitleId)
	{
		String sql = "select * from SecondLevelTitle where ParentTitle="+parentTitleId;
		ResultSet rs = db.executeQuery(sql);
		ArrayList lst = new ArrayList(); 
		SecondLevelTitle second = null;
		try {
			while(rs.next()) {
				second = new SecondLevelTitle();
				second.setId(rs.getLong("Id"));
				second.setTitleName(rs.getString("Title"));
				second.setFilePath(rs.getString("FilePath"));
				second.setCreater(rs.getString("Creater"));
				second.setCreatTime(rs.getString("CreatTime"));
				second.setParentTitle(rs.getLong("ParentTitle"));
				lst.add(second);
			}
			return lst;
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return null;
		}
	}
	
	public void Close(){
		this.db.Close();
	}

}

⌨️ 快捷键说明

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