index.java

来自「NTsky新闻发布v1.0(提供JavaBean)」· Java 代码 · 共 157 行

JAVA
157
字号
package ntsky.news;
import java.sql.*;
import ntsky.database.*;

public class Index{
	private	int sum;
	private int classid;
	private int id;
	private ResultSet rs = null;
	private int counter;

	//文章的总值(aritcleid)(判断有无记录,如没有的话就要求先添加记录)
	public int sum() throws Exception{
		String sql = "select count(articleid) as t from article where state=1;";
		DBConnect dbc = new DBConnect();
		rs=dbc.executeQuery(sql);
		if(rs != null){	
			rs.next();
			sum = rs.getInt("t");
			return sum;
		}
		else{
			return 0;
		}
	}
	//时间
	public ResultSet rs_time() throws Exception{
		String sql = "select time from article order by date desc limit 0,1;";
		DBConnect dbc = new DBConnect();
		rs = dbc.executeQuery(sql);
		return rs;
	}
	//栏目
	public int classid(int classid) throws Exception{
		this.classid = classid;
		return classid;
	}
	/**
	public int id(int id) throws Exception{
		this.id = id;
		return id;
	}
	*/
	public ResultSet rs_column(){
		String sql = "select content from class where classid=?;";
		try{
			DBConnect dbc = new DBConnect(sql);
			dbc.setInt(1,classid);
			rs = dbc.executeQuery();
		}
		catch(Exception e){
			System.out.println("rs_column:" + e.getMessage());
		}
		return rs;
	}
	//类别
	/**
	public ResultSet rs_kind(){
		String sql = "select content,classid from kind where id=?;";
		try{
			DBConnect dbc = new DBConnect(sql);
			dbc.setInt(1,id);
			rs = dbc.executeQuery();
		}
		catch(Exception e){
			System.out.println("rs_kind:" + e.getMessage());
		}
		return rs;
	}
	*/
	//置定的文章最新加入(取前2条)
	public ResultSet rs_new_top(){
		String sql = "select articleid,title,classid,id,author,date,time from article where state=1 and top=1 order by time desc limit 0,1;";
		try{
			DBConnect dbc = new DBConnect();
			rs = dbc.executeQuery(sql);
		}
		catch(Exception e){
			System.out.print("rs_new_top" +e.getMessage());
		}
		return rs;
	}
	//最新的文章
	public ResultSet rs_new(){
		String sql = "select articleid,title,classid,id,author,date from article where state=1 and top=0 order by time desc limit 0,9;";
		try{
			DBConnect dbc = new DBConnect();
			rs = dbc.executeQuery(sql);
		}
		catch(Exception e){
			System.out.print("rs_new" +e.getMessage());
		}
		return rs;
	}
	//点击次数
	public ResultSet rs_hot(){
		String sql = "select articleid,hits,title,date from article where state=1 order by hits desc limit 0,10;";
		try{
			DBConnect dbc = new DBConnect();
			rs = dbc.executeQuery(sql);
		}
		catch(Exception e){
			System.out.print("rs_hot" +e.getMessage());
		}
		return rs;
	}
	//文章总数
	public int ateCounter(){
		String sql = "select count(articleid) as counter from article where state=1;";
		try{
			DBConnect dbc = new DBConnect();
			rs = dbc.executeQuery(sql);
			rs.next();
			counter = rs.getInt("counter");
		}
		catch(Exception e){
			System.out.print("文章总数");
		}
		return counter;
	}
	//注册用户总数
	public int usrCounter(){
		String sql = "select count(user) as counter from usr;";
		try{
			DBConnect dbc = new DBConnect();
			rs = dbc.executeQuery(sql);
			rs.next();
			counter = rs.getInt("counter");
		}
		catch(Exception e){
			System.out.print("用户总数");
		}
		return counter;
	}
	//访问总数
	public int counter() throws Exception{
		String sql = "select counter from common;";
		DBConnect dbc = new DBConnect();
		rs = dbc.executeQuery(sql);
		rs.next();
		counter = rs.getInt("counter");
		return counter;
	}
	//更新访问数
	public void upCounter() throws Exception{
		String sql = "update common set counter=?+1;";
		DBConnect dbc = new DBConnect(sql);
		dbc.setInt(1,counter);
		dbc.executeUpdate();
	}
	//关闭指针
	public void close() throws Exception{
		if(rs != null){
			rs.close();
		}
	}
}

⌨️ 快捷键说明

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