📄 newsshow.java
字号:
}
catch(NullPointerException nullE){
System.out.print("NewsShow isNews() " +nullE.getMessage());
Debug.writeLog("NewsShow isNews(), Exception Occured ! Info :" + nullE.getLocalizedMessage());
}
}
catch(SQLException sqlE){
System.out.print("NewsShow isNews() " +sqlE.getMessage());
Debug.writeLog("NewsShow isNews(), Exception Occured ! Info :" + sqlE.getLocalizedMessage());
}
finally{
sdbo.Close();
}
return isNewNews;
}
/**
* 最新的文章(不用前缀)
*/
public Iterator newNews(){
ResultSet rs=null;
if (sdbo==null)
sdbo = SQLDBOperator.getInstance("Connection");
Vector vector=new Vector();
String strSql = "select newsId,classId,headTitle from news where state=1 and top=0 order by newsTime desc limit 0,9;";
try{
rs = sdbo.executeQuery(strSql);
try{
while(rs.next()){
NEWSTable tableNews = new NEWSTable();
tableNews.setNewsId(rs.getInt("newsId"));
tableNews.setHeadTitle(rs.getString("headTitle"));
tableNews.setClassId(rs.getInt("classId"));
vector.add(tableNews);
}
rs.close();
}
catch(NullPointerException nullE){
System.out.print("NewsShow newNews() " +nullE.getMessage());
Debug.writeLog("NewsShow newNews(), Exception Occured ! Info :" + nullE.getLocalizedMessage());
}
}
catch(SQLException sqlE){
System.out.print("NewsShow newNews() " +sqlE.getMessage());
Debug.writeLog("NewsShow newNews(), Exception Occured ! Info :" + sqlE.getLocalizedMessage());
}
finally{
sdbo.Close();
}
return vector.iterator();
}
/**
* 热门文章
*/
public Iterator hotNews(){
ResultSet rs=null;
if (sdbo==null)
sdbo = SQLDBOperator.getInstance("Connection");
Vector vector=new Vector();
String strSql = "select newsId,headTitle,hits,DATE_FORMAT(newsTime,'%Y-%m-%d') as time from news where state=1 order by hits desc limit 0,10;";
try{
rs = sdbo.executeQuery(strSql);
try{
while(rs.next()){
NEWSTable tableNews = new NEWSTable();
tableNews.setNewsId(rs.getInt("newsId"));
tableNews.setHeadTitle(rs.getString("headTitle"));
tableNews.setHits(rs.getInt("hits"));
tableNews.setNewsTime(rs.getString("time"));
vector.add(tableNews);
}
rs.close();
}
catch(NullPointerException nullE){
System.out.print("NewsShow newNews() " +nullE.getMessage());
Debug.writeLog("NewsShow newNews(), Exception Occured ! Info :" + nullE.getLocalizedMessage());
}
}
catch(SQLException sqlE){
System.out.print("NewsShow newNews() " +sqlE.getMessage());
Debug.writeLog("NewsShow newNews(), Exception Occured ! Info :" + sqlE.getLocalizedMessage());
}
finally{
sdbo.Close();
}
return vector.iterator();
}
/**
* 列出文章
*/
public Iterator listNews(int newsId){
ResultSet rs=null;
if (sdbo==null)
sdbo = SQLDBOperator.getInstance("Connection");
Vector vector=new Vector();
String strSql = "select * from news where newsId=?;";
try{
sdbo.prepareStatement(strSql);
sdbo.setInt(1,newsId);
rs = sdbo.executeQuery();
try{
while(rs.next()){
NEWSTable tableNews = new NEWSTable();
tableNews.setNewsId(rs.getInt("newsId"));
tableNews.setClassId(rs.getInt("classId"));
tableNews.setKindId(rs.getInt("kindId"));
tableNews.setMyOther(rs.getInt("myOther"));
tableNews.setHeadTitle(rs.getString("headTitle"));
tableNews.setContent(rs.getString("content"));
tableNews.setConnect(rs.getString("connect"));
tableNews.setAuthor(rs.getString("author"));
tableNews.setEditor(rs.getString("editor"));
tableNews.setNewsFrom(rs.getString("newsFrom"));
tableNews.setHits(rs.getInt("hits"));
tableNews.setNewsTime(rs.getString("newsTime"));
vector.add(tableNews);
}
rs.close();
}
catch(NullPointerException nullE){
System.out.print("NewsShow newNews() " +nullE.getMessage());
Debug.writeLog("NewsShow newNews(), Exception Occured ! Info :" + nullE.getLocalizedMessage());
}
}
catch(SQLException sqlE){
System.out.print("NewsShow newNews() " +sqlE.getMessage());
Debug.writeLog("NewsShow newNews(), Exception Occured ! Info :" + sqlE.getLocalizedMessage());
}
finally{
sdbo.Close();
}
return vector.iterator();
}
//是否为原创
public String valueMyOther(int intMyOther){
String strMyOther="原创";
if(intMyOther==1){
strMyOther="转载";
}
return strMyOther;
}
/**
* 更新文章的阅读次数
*/
public void upReadTime(int newsId){
if (sdbo==null)
sdbo = SQLDBOperator.getInstance("Connection");
String strSql = "update news set hits=hits+1 where newsId='"+newsId+"';";
try{
sdbo.executeUpdate(strSql);
}
catch(Exception e){
System.out.print("NewsShow newNews() " +e.getMessage());
Debug.writeLog("NewsShow newNews(), Exception Occured ! Info :" + e.getLocalizedMessage());
}
finally{
sdbo.Close();
}
}
/**
* 热门文章(listHotNews)
*/
public Iterator listHotNews(int kindId){
if (sdbo==null)
sdbo = SQLDBOperator.getInstance("Connection");
ResultSet rs=null;
Vector vector=new Vector();
String strSql = "select newsId,headTitle from news where state=1 and KindId=? order by hits desc limit 0,8;";
try{
sdbo.prepareStatement(strSql);
sdbo.setInt(1,kindId);
rs = sdbo.executeQuery();
try{
while(rs.next()){
NEWSTable tableNews = new NEWSTable();
tableNews.setNewsId(rs.getInt("newsId"));
tableNews.setHeadTitle(rs.getString("headTitle"));
vector.add(tableNews);
}
rs.close();
}
catch(NullPointerException nullE){
System.out.print("NewsShow newNews() " +nullE.getMessage());
Debug.writeLog("NewsShow newNews(), Exception Occured ! Info :" + nullE.getLocalizedMessage());
}
}
catch(SQLException sqlE){
System.out.print("NewsShow newNews() " +sqlE.getMessage());
Debug.writeLog("NewsShow newNews(), Exception Occured ! Info :" + sqlE.getLocalizedMessage());
}
finally{
sdbo.Close();
}
return vector.iterator();
}
//栏目的值
public String strClass(int classId){
if (sdbo==null)
sdbo = SQLDBOperator.getInstance("Connection");
ResultSet rs=null;
String strClass=null;
String strSql = "select content from newsclass where classId=?;";
try{
sdbo.prepareStatement(strSql);
sdbo.setInt(1,classId);
rs = sdbo.executeQuery();
try{
rs.next();
strClass=rs.getString("content");
rs.close();
}
catch(NullPointerException nullE){
System.out.print("NewsShow newNews() " +nullE.getMessage());
Debug.writeLog("NewsShow newNews(), Exception Occured ! Info :" + nullE.getLocalizedMessage());
}
}
catch(SQLException sqlE){
System.out.print("NewsShow newNews() " +sqlE.getMessage());
Debug.writeLog("NewsShow newNews(), Exception Occured ! Info :" + sqlE.getLocalizedMessage());
}
finally{
sdbo.Close();
}
return strClass;
}
//类别的值
public String strKind(int kindId){
if (sdbo==null)
sdbo = SQLDBOperator.getInstance("Connection");
ResultSet rs=null;
String strKind=null;
String strSql = "select content from newskind where kindId=?;";
try{
sdbo.prepareStatement(strSql);
sdbo.setInt(1,kindId);
rs = sdbo.executeQuery();
try{
rs.next();
strKind=rs.getString("content");
rs.close();
}
catch(NullPointerException nullE){
System.out.print("NewsShow newNews() " +nullE.getMessage());
Debug.writeLog("NewsShow newNews(), Exception Occured ! Info :" + nullE.getLocalizedMessage());
}
}
catch(SQLException sqlE){
System.out.print("NewsShow newNews() " +sqlE.getMessage());
Debug.writeLog("NewsShow newNews(), Exception Occured ! Info :" + sqlE.getLocalizedMessage());
}
finally{
sdbo.Close();
}
return strKind;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -