listarticle.java
来自「NTsky新闻发布v1.0(提供JavaBean)」· Java 代码 · 共 193 行
JAVA
193 行
package ntsky.news;
import java.sql.*;
import javax.servlet.http.*;
import ntsky.database.*;
public class ListArticle{
private int articleid;
private ResultSet rs = null;
private int classid;
private String column = null;
private int id;
private String kind = null;
private int kind_total;
private int sum_reply;
private int sum_conn;
//articleid
public int getarticleid(HttpServletRequest request,String Sid){
try{
articleid = Integer.parseInt(request.getParameter(Sid).trim());
}
catch(Exception e){
System.out.println("articleid" +e.getMessage());
}
return articleid;
}
//指针
public ResultSet rs_listarticle(){
String sql = "select classid,id,title,content,author,editor,articlefrom,connection,myorothers,time from article where articleid=?;";
try{
DBConnect dbc = new DBConnect(sql);
dbc.setInt(1,articleid);
rs = dbc.executeQuery();
}
catch(Exception e){
System.out.println("rs" +e.getMessage());
}
if(rs!=null){
return rs;
}else{
return rs=null;
}
}
//栏目
public int classid(int classid){
this.classid = classid;
return classid;
}
public String column(){
String sql = "select content from class where classid=?";
try{
DBConnect dbc = new DBConnect(sql);
dbc.setInt(1,classid);
rs = dbc.executeQuery();
if(rs!=null){
rs.next();
column = rs.getString("content");
}
else{
column = "";
}
}
catch(Exception e){
System.out.println("column" +e.getMessage());
}
return column;
}
//类别
public int id(int id){
this.id = id;
return id;
}
//判断有无类别
/**
public int kind_total(){
String sql = "select count(id) as kind_total from kind where id=?;";
try{
DBConnect dbc = new DBConnect(sql);
dbc.setInt(1,id);
rs = dbc.executeQuery();
rs.next();
kind_total = rs.getInt("kind_total");
}
catch(Exception e){
System.out.print("kind" +e.getMessage());
}
return kind_total;
}
*/
public String kind(){
String sql = "select content from kind where id=?;";
try{
DBConnect dbc = new DBConnect(sql);
dbc.setInt(1,id);
rs = dbc.executeQuery();
if(id != 0){
rs.next();
kind = rs.getString("content");
}
else{
kind = " ";
}
}
catch(Exception e){
System.out.print("kind" +e.getMessage());
}
return kind;
}
//点击次数
public ResultSet rs_hot(){
String sql = "select articleid,title 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 void addhits(){
String sql = "update article set hits=hits+1 where articleid=?;";
try{
DBConnect dbc = new DBConnect(sql);
dbc.setInt(1,articleid);
dbc.executeUpdate();
}
catch(Exception e){
System.out.println("hits" +e.getMessage());
}
}
//评论
public int sumreply(){
String sql = "select count(*) as t from reply where articleid=?;";
try{
DBConnect dbc = new DBConnect(sql);
dbc.setInt(1,articleid);
rs = dbc.executeQuery();
rs.next();
sum_reply = rs.getInt("t");
}
catch(Exception e){
System.out.println("reply" +e.getMessage());
}
return sum_reply;
}
public ResultSet reply(){
String sql = "select * from reply where articleid=? order by time desc;";
try{
DBConnect dbc = new DBConnect(sql);
dbc.setInt(1,articleid);
rs = dbc.executeQuery();
}
catch(Exception e){
System.out.println("reply" +e.getMessage());
}
return rs;
}
//相关文章
public int sumconn(String connect){
String sql = "select count(*) as t from article where state=1 and connection like '%"+connect+"%';";
try{
DBConnect dbc = new DBConnect();
rs = dbc.executeQuery(sql);
rs.next();
sum_reply = rs.getInt("t");
}
catch(Exception e){
System.out.println("reply" +e.getMessage());
}
return sum_reply;
}
public ResultSet conn(String connect){
String sql = "select * from article where state=1 and connection like '%"+connect+"%' order by time desc limit 0,6;";
try{
DBConnect dbc = new DBConnect();
rs = dbc.executeQuery(sql);
}
catch(Exception e){
System.out.println("reply" +e.getMessage());
}
return rs;
}
//关闭指针
public void close() throws Exception{
if(rs != null){
rs.close();
}
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?