/***********************************************
/*
/*文章查询、更新、删除等等操作
/*
/******************************************* */
package com.index;
import java.sql.*;
import java.util.ArrayList;
import com.util.*;
import com.index.User;
public class Know {
public int id;
public String title = "";
public String content="";
public String asker="";
public String createtime="";
public String settletime="";
public int flag=1;
public String type="";
public int award;
public String replier="";
public int answerd;
public int sortid;
public int bestid;
public String add_content="";
public Know() {
}
public ArrayList ViewAll() throws Exception{
Connection conn=null;
PreparedStatement stmt =null;
ResultSet rs =null;
String sql ="select A.title,B.name,A.id,A.award from know_article A join know_sortid B on A.sortid=B.id order by A.id desc";
ArrayList<Know> result=new ArrayList<Know>();
try{
conn=DBConn.getConn();
stmt= conn.prepareStatement(sql);
rs = stmt.executeQuery();
while (rs.next()){
Know article=new Know();
article.title=rs.getString(1).trim();
article.type=rs.getString(2).trim();
article.id=rs.getInt(3);
article.award=rs.getInt(4);
result.add(article);
}
}
catch(Exception e){
e.printStackTrace();
}
finally{
try{
if(rs!=null)
rs.close();
if(stmt!=null)
stmt.close();
if(conn!=null)
conn.close();
}catch(Exception e){
e.printStackTrace();
}
}
return result;
}
//查看已解决问题
public ArrayList ViewSettled() throws Exception{
Connection conn=null;
PreparedStatement stmt =null;
ResultSet rs =null;
String sql ="select * from know_article A join know_sortid B on A.sortid=B.id where A.flag=2 order by A.settletime desc";
ArrayList<Know> result=new ArrayList<Know>();
try{
conn=DBConn.getConn();
stmt= conn.prepareStatement(sql);
rs = stmt.executeQuery();
while (rs.next()){
Know article=new Know();
article.title=rs.getString("title").trim();
article.type=rs.getString("name").trim();
article.id=rs.getInt("id");
article.replier=rs.getString("replier");
result.add(article);
}
}
catch(Exception e){
e.printStackTrace();
}
finally{
try{
if(rs!=null)
rs.close();
if(stmt!=null)
stmt.close();
if(conn!=null)
conn.close();
}catch(Exception e){
e.printStackTrace();
}
}
return result;
}
//查看待解决问题
public ArrayList ViewUnsettled() throws Exception{
Connection conn=null;
PreparedStatement stmt =null;
ResultSet rs =null;
String sql ="select A.title,B.name,A.id,A.award from know_article A join know_sortid B " +
"on A.sortid=B.id where A.flag=1 order by A.id desc";
ArrayList<Know> result=new ArrayList<Know>();
try{
conn=DBConn.getConn();
stmt= conn.prepareStatement(sql);
rs = stmt.executeQuery();
while (rs.next()){
Know article=new Know();
article.title=rs.getString(1).trim();
article.type=rs.getString(2).trim();
article.id=rs.getInt(3);
article.award=rs.getInt(4);
result.add(article);
}
}
catch(Exception e){
e.printStackTrace();
}
finally{
try{
if(rs!=null)
rs.close();
if(stmt!=null)
stmt.close();
if(conn!=null)
conn.close();
}catch(Exception e){
e.printStackTrace();
}
}
return result;
}
//查看零回答问题
public ArrayList ViewUnAnswerd() throws Exception{
Connection conn=null;
PreparedStatement stmt =null;
ResultSet rs =null;
String sql ="select A.title,B.name,A.id,A.award,A.createtime from know_article A join know_sortid B " +
"on A.sortid=B.id where A.answerd=0 order by A.id desc";
ArrayList<Know> result=new ArrayList<Know>();
try{
conn=DBConn.getConn();
stmt= conn.prepareStatement(sql);
rs = stmt.executeQuery();
while (rs.next()){
Know article=new Know();
article.title=rs.getString(1).trim();
article.type=rs.getString(2).trim();
article.id=rs.getInt(3);
article.award=rs.getInt(4);
article.createtime=rs.getString(5);
result.add(article);
}
}
catch(Exception e){
e.printStackTrace();
}
finally{
try{
if(rs!=null)
rs.close();
if(stmt!=null)
stmt.close();
if(conn!=null)
conn.close();
}catch(Exception e){
e.printStackTrace();
}
}
return result;
}
//查询问题
public ArrayList Search(String key) throws Exception{
Connection conn=null;
PreparedStatement stmt =null;
ResultSet rs =null;
String sql ="select A.title,B.name,A.id,A.flag from know_article A join know_sortid B " +
"on A.sortid=B.id where A.title like ? order by A.id desc";
ArrayList<Know> result=new ArrayList<Know>();
try{
conn=DBConn.getConn();
stmt= conn.prepareStatement(sql);
stmt.setString(1, "%"+ key + "%");
rs = stmt.executeQuery();
while (rs.next()){
Know article=new Know();
article.title=rs.getString(1).trim();
article.type=rs.getString(2).trim();
article.id=rs.getInt(3);
article.flag=rs.getInt(4);
result.add(article);
}
}
catch(Exception e){
e.printStackTrace();
}
finally{
try{
if(rs!=null)
rs.close();
if(stmt!=null)
stmt.close();
if(conn!=null)
conn.close();
}catch(Exception e){
e.printStackTrace();
}
}
return result;
}
//查询我的提问
public ArrayList myAsk(String nickname) throws Exception{
Connection conn=null;
PreparedStatement stmt =null;
ResultSet rs =null;
String sql ="select A.title,B.name,A.id,A.flag,A.answerd from know_article A join know_sortid B " +
"on A.sortid=B.id where A.asker=? order by A.id desc";
ArrayList<Know> result=new ArrayList<Know>();
try{
conn=DBConn.getConn();
stmt= conn.prepareStatement(sql);
stmt.setString(1,nickname);
rs = stmt.executeQuery();
while (rs.next()){
Know article=new Know();
article.title=rs.getString(1).trim();
article.type=rs.getString(2).trim();
article.id=rs.getInt(3);
article.flag=rs.getInt(4);
article.answerd=rs.getInt(5);
result.add(article);
}
}
catch(Exception e){
e.printStackTrace();
}
finally{
try{
if(rs!=null)
rs.close();
if(stmt!=null)
stmt.close()