📄 personal.java
字号:
package com.ntsky.news;
import com.ntsky.common.CodeFilter;
import com.ntsky.common.Debug;
import com.ntsky.database.SQLDBOperator;
import com.ntsky.persistence.NEWSTable;
import java.io.UnsupportedEncodingException;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Iterator;
import java.util.Vector;
public class Personal {
private SQLDBOperator sdbo;
private String user;
private ResultSet rs;
private int total;
public Personal() {
sdbo = null;
user = null;
rs = null;
}
public String setUser(String user) {
this.user = user;
return user;
}
public String timePersonal() {
if (sdbo == null)
sdbo = SQLDBOperator.getInstance("Connection");
String sql = "select regTime from newsusr where userName=?;";
String time = null;
try {
sdbo.prepareStatement(sql);
sdbo.setString(1, user);
rs = sdbo.executeQuery();
rs.next();
time = rs.getString("regTime");
} catch (Exception e) {
System.out.print("Personal timePersonal() info :" + e.getMessage());
Debug
.writeLog("Personal timePersonal(), Exception Occured ! Info :"
+ e.getLocalizedMessage());
} finally {
sdbo.Close();
}
return time;
}
public int sumPersonal() {
if (sdbo == null)sdbo = SQLDBOperator.getInstance("Connection");
String sql = "select count(newsId) as sum from news where author=? and state=0 and tag=0;";
try {
sdbo.prepareStatement(sql);
sdbo.setString(1, user);
rs = sdbo.executeQuery();
rs.next();
total = rs.getInt("sum");
rs.close();
} catch (Exception e) {
System.out.print("Personal sumPersonal() info :" + e.getMessage());
Debug.writeLog("Personal sumPersonal(), Exception Occured ! Info :"
+ e.getLocalizedMessage());
} finally {
sdbo.Close();
}
return total;
}
public String pdmPersonal() {
String grade = null;
if (sdbo == null)
sdbo = SQLDBOperator.getInstance("Connection");
// if (total <= 10)
// purview = 1;
// else if (total > 10 && total <= 30)
// purview = 2;
// else if (total > 30)
// purview = 3;
String sql = "select grade from newspopedom where gradeId=?;";
try {
sdbo.prepareStatement(sql);
sdbo.setInt(1, 4);
ResultSet rs = sdbo.executeQuery();
rs.next();
grade = new String(rs.getString("grade").getBytes("ISO-8859-1"),"gbk");
rs.close();
} catch (Exception e) {
System.out.print("Personal pdmPersonal() info :" + e.getMessage());
Debug.writeLog("Personal pdmPersonal(), Exception Occured ! Info :" + e.getLocalizedMessage());
} finally {
sdbo.Close();
}
return grade;
}
public Iterator enNews() {
Vector vector = new Vector();
if (sdbo == null)
sdbo = SQLDBOperator.getInstance("Connection");
String sql = "select newsId,headTitle,DATE_FORMAT(newsTime,'%Y-%m-%d') as time from news where state=1 and tag=0 and author=?;";
try {
sdbo.prepareStatement(sql);
sdbo.setString(1, user);
NEWSTable tableNews;
for (rs = sdbo.executeQuery(); rs.next(); vector.add(tableNews)) {
tableNews = new NEWSTable();
tableNews.setNewsId(rs.getInt("newsId"));
tableNews.setHeadTitle(rs.getString("headTitle"));
tableNews.setNewsTime(rs.getString("time"));
}
rs.close();
} catch (Exception e) {
System.out.print("Personal pdmPersonal() info :" + e.getMessage());
Debug.writeLog("Personal enNews(), Exception Occured ! Info :"
+ e.getLocalizedMessage());
} finally {
sdbo.Close();
}
return vector.iterator();
}
public int sumUnNews() {
if (sdbo == null)sdbo = SQLDBOperator.getInstance("Connection");
int sum = 0;
String sql = "select count(newsId) as sum from news where state=0 and tag=0 and author=?;";
try {
sdbo.prepareStatement(sql);
sdbo.setString(1, user);
rs = sdbo.executeQuery();
rs.next();
sum = rs.getInt("sum");
rs.close();
} catch (SQLException sqlE) {
System.out.print("Personal sumUnNews() info :" + sqlE.getMessage());
Debug.writeLog("Personal sumUnNews(), Exception Occured ! Info :"
+ sqlE.getLocalizedMessage());
} catch (NullPointerException nullE) {
System.out
.print("Personal sumUnNews() info :" + nullE.getMessage());
Debug.writeLog("Personal sumUnNews(), Exception Occured ! Info :"
+ nullE.getLocalizedMessage());
} finally {
sdbo.Close();
}
return sum;
}
public Iterator unNews() {
Vector vector = new Vector();
if (sdbo == null)
sdbo = SQLDBOperator.getInstance("Connection");
String sql = "select newsId,headTitle,newsTime from news where state=0 and tag=0 and author=? order by newsTime desc;";
try {
sdbo.prepareStatement(sql);
sdbo.setString(1, user);
rs = sdbo.executeQuery();
while (rs.next()) {
NEWSTable tableNews = new NEWSTable();
tableNews.setNewsId(rs.getInt("newsId"));
tableNews.setHeadTitle(CodeFilter.toUbbHtml(new String(rs.getString("headTitle").getBytes("ISO-8859-1"), "gbk")));
tableNews.setNewsTime(CodeFilter.toUbbHtml(rs.getString("newsTime")));
vector.add(tableNews);
}
rs.close();
} catch (SQLException sqlE) {
System.out.print("Personal unNews() info :" + sqlE.getMessage());
Debug.writeLog("Personal unNews(), Exception Occured ! Info :" + sqlE.getLocalizedMessage());
} catch (UnsupportedEncodingException nullE) {
System.out.print("Personal unNews() info :" + nullE.getMessage());
Debug.writeLog("Personal unNews(), Exception Occured ! Info :" + nullE.getLocalizedMessage());
} finally {
sdbo.Close();
}
return vector.iterator();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -