?? search.java
字號:
package ntsky.common;
import java.sql.*;
import javax.servlet.http.*;
import ntsky.database.*;
import ntsky.common.*;
public class Search{
public String search = null;
public int select;
private ResultSet rs = null;
private int total;
private int sum;
//獲取字符串的值
public void setSearch(String search){
this.search = search;
}
public String getSearch(){
return CodeFilter.toHtml(search);
}
//select的值
public void setSelect(int select){
this.select = select;
}
public int getSelect(){
return select;
}
//記錄總數
public int total(String search){
if((select == 0)){
try{
String sql = "select count(articleid) as t from article where state=1 and title like '%"+search+"%';";
DBConnect dbc = new DBConnect();
rs = dbc.executeQuery(sql);
rs.next();
total = rs.getInt("t");
}
catch(Exception e){
System.out.print("rs_result error");
}
return total;
}
else{
try{
String sql = "select count(articleid) as t from article where state=1 and content like '%"+search+"%';";
DBConnect dbc = new DBConnect();
rs = dbc.executeQuery(sql);
rs.next();
total = rs.getInt("t");
}
catch(Exception e){
System.out.print("rs_result error");
}
return total;
}
}
//搜索
public ResultSet rs_result(String search){
DBConnect dbc = new DBConnect();
if(select == 0){
try{
String sql = "select articleid,title from article where state=1 and title like '%"+search+"%';";
rs = dbc.executeQuery(sql);
}
catch(Exception e){
System.out.print("rs_result error");
}
return rs;
}
else{
try{
String sql = "select articleid,title from article where state=1 and content like '%"+search+"%';";
rs = dbc.executeQuery(sql);
}
catch(Exception e){
System.out.print("rs_result error");
}
return rs;
}
}
//文章的總值(服務器配置)(判斷有無記錄,如沒有的話就要求先添加記錄)
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_hot(){
String sql = "select articleid,title from article where state=1 order by hits desc limit 0,6;";
try{
DBConnect dbc = new DBConnect();
rs = dbc.executeQuery(sql);
}
catch(Exception e){
System.out.print("rs_hot" +e.getMessage());
}
return rs;
}
//關閉指針
public void close() throws Exception{
if(rs != null){
rs.close();
rs = null;
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -