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

📄 news.java

📁 java语言编写的程序
💻 JAVA
字号:
/**
 * 
 */
package cn.lab.object;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.Vector;
import cn.lab.dbquery.DataProcess;
import cn.lab.object.Pageable;
/**
 * @author Administrator
 *
 */
public class News {
	private int id;
	private String title;
	private String content;
	private String time;
	News()
	{
	}
	public News(int id, String title, String content, String time) {
		this.id = id;
		this.title = title;
		this.content = content;
		this.time = time;
	}
	/**
	 * @return the content
	 */
	public String getContent() {
		return content;
	}
	/**
	 * @param content the content to set
	 */
	public void setContent(String content) {
		this.content = content;
	}
	/**
	 * @return the id
	 */
	public int getId() {
		return id;
	}
	/**
	 * @param id the id to set
	 */
	public void setId(int id) {
		this.id = id;
	}
	/**
	 * @return the time
	 */
	public String getTime() {
		return time;
	}
	/**
	 * @param time the time to set
	 */
	public void setTime(String time) {
		this.time = time;
	}
	/**
	 * @return the title
	 */
	public String getTitle() {
		return title;
	}
	/**
	 * @param title the title to set
	 */
	public void setTitle(String title) {
		this.title = title;
	}
	
	public static Vector search(String strSql,int page)throws Exception
	{
		Vector Items = new Vector();
		Connection con=DataProcess.getConnection();
		PreparedStatement pStmt = null;
		ResultSet rs = null;
		try
		{
			pStmt = con.prepareStatement(strSql, 
					ResultSet.TYPE_SCROLL_INSENSITIVE,
					ResultSet.CONCUR_READ_ONLY);
			rs = pStmt.executeQuery();
			Pageable pgb = new Pageable(rs);
			pgb.setPageSize(5);
			pgb.gotoPage(page);
			
			rs.absolute(pgb.getRowsCount());
			int i=0;
			do
			{
				Items.add(new 
						News(rs.getInt("id"),rs.getString("title"),rs.getString("content"),
						rs.getString("datetime")));
				i++;
			}while(rs.next()&&i<pgb.getCurrentPageRowsCount());
			return Items;
		}finally{
			try{
				rs.close();
				pStmt.close();
				con.close();
			}catch(Exception e)
			{
				e.printStackTrace();
			}
		}
	}
	public static News getNews(int ID)
	{
		String selectStr = "select* from news where id="+ID;
		Connection con = DataProcess.getConnection();
			
		News news = new News();
		try
		{
			Statement stmt= con.createStatement();
			ResultSet rs = stmt.executeQuery(selectStr);
			if(rs.next())
			{
				String title = rs.getString("title");
				String content = rs.getString("content");
				String time = rs.getString("time");
				
				news.setId(ID);
				news.setTitle(title);
				news.setContent(content);
				news.setTime(time);
			}
			rs.close();
			stmt.close();
			con.close();
			return news;
		}catch(Exception e)
		{
			e.printStackTrace();
			return null;
		}
	}
}

⌨️ 快捷键说明

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