?? singlerecordmodel.java
字號:
/*
* SingleRecordModel.java
*
* Created on 2007年3月18日, 上午11:26
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/
package News.ProcessData;
import News.Common.ChineseEncode;
import java.sql.*;
import java.util.*;
import News.Common.DBManager;
/**
*
* @author Owner
*/
public class SingleRecordModel {
private ResultSet rs=null;
private Connection conn=null;
private PreparedStatement ps=null;
/** Creates a new instance of SingleRecordModel */
public SingleRecordModel() {
}
public Hashtable LinkRecord(String IDparam)
{
int ID=0;
Hashtable ht=new Hashtable();
try{
ID=Integer.parseInt(IDparam);
}catch(NumberFormatException e){ID=-1;}
try{
conn=DBManager.getConnection();
ps=conn.prepareStatement("select * from Links where ID=?");
ps.setInt(1,ID);
rs=ps.executeQuery();
if(rs.next())
{
ht.put("ID",rs.getString("ID"));
ht.put("Name",rs.getString("Name"));
ht.put("URL",rs.getString("URL"));
ht.put("Logo",rs.getString("Logo"));
}else {return null;}
}catch(SQLException e){System.out.println(e.getMessage());return null;}
finally{
try{
if(rs!=null){rs.close();}
if(ps!=null){ps.close();}
if(conn!=null){conn.close();}
}catch(SQLException e1){System.out.println(e1.getMessage());}}
return ht;
}
public Hashtable NoticeRecord(String IDparam)
{
int ID=0;
Hashtable ht=new Hashtable();
try{
ID=Integer.parseInt(IDparam);
}catch(NumberFormatException e){ID=-1;}
try{
conn=DBManager.getConnection();
ps=conn.prepareStatement("select * from Notice where ID=?");
ps.setInt(1,ID);
rs=ps.executeQuery();
if(rs.next())
{
ht.put("ID",rs.getString("ID"));
ht.put("Message",rs.getString("Message"));
ht.put("Time",rs.getString("Time"));
}else {return null;}
}catch(SQLException e){System.out.println(e.getMessage());return null;}
finally{
try{
if(rs!=null){rs.close();}
if(ps!=null){ps.close();}
if(conn!=null){conn.close();}
}catch(SQLException e1){System.out.println(e1.getMessage());}}
return ht;
}
public Hashtable CatalogRecord(String IDparam)
{
int ID=0;
Hashtable ht=new Hashtable();
try{
ID=Integer.parseInt(IDparam);
}catch(NumberFormatException e){ID=-1;}
try{
conn=DBManager.getConnection();
ps=conn.prepareStatement("select * from Catalogs where ID=?");
ps.setInt(1,ID);
rs=ps.executeQuery();
if(rs.next())
{
ht.put("ID",rs.getString("ID"));
ht.put("Title",rs.getString("Title"));
ht.put("LogoURL",rs.getString("LogoURL"));
ht.put("ModifyTime",rs.getString("ModifyTime"));
}else {return null;}
}catch(SQLException e){System.out.println(e.getMessage());return null;}
finally{
try{
if(rs!=null){rs.close();}
if(ps!=null){ps.close();}
if(conn!=null){conn.close();}
}catch(SQLException e1){System.out.println(e1.getMessage());}}
return ht;
}
public Hashtable NewsRecord(String IDparam)
{
int ID=0;
Hashtable ht=new Hashtable();
try{
ID=Integer.parseInt(IDparam);
}catch(NumberFormatException e){ID=-1;}
try{
conn=DBManager.getConnection();
ps=conn.prepareStatement("select * from News as n,Catalogs as c where n.parentId=c.ID and n.ID=?");
ps.setInt(1,ID);
rs=ps.executeQuery();
if(rs.next())
{
ht.put("ID",rs.getString(1));
ht.put("Title",rs.getString(3));
ht.put("Author",rs.getString(4));
ht.put("ModifyTime",rs.getString(6));
ht.put("Content",rs.getString(7));
ht.put("CatalogName",rs.getString(9));
}else {return null;}
}catch(SQLException e){System.out.println(e.getMessage());return null;}
finally{
try{
if(rs!=null){rs.close();}
if(ps!=null){ps.close();}
if(conn!=null){conn.close();}
}catch(SQLException e1){System.out.println(e1.getMessage());}}
return ht;
}
public Hashtable SiteSettingRecord()
{
Hashtable ht=new Hashtable();
try{
conn=DBManager.getConnection();
ps=conn.prepareStatement("select top 1 * from SiteSetting");
rs=ps.executeQuery();
if(rs.next())
{
ht.put("SiteName",rs.getString("SiteName"));
ht.put("SiteURL",rs.getString("SiteURL"));
ht.put("CompanyName",rs.getString("CompanyName"));
ht.put("CompanyURL",rs.getString("CompanyURL"));
ht.put("MetaDescription",rs.getString("MetaDescription"));
ht.put("MetaKeywords",rs.getString("MetaKeywords"));
ht.put("BottomAD",rs.getString("BottomAD"));
ht.put("TopBanner",rs.getString("TopBanner"));
ht.put("IsCheckCode",rs.getString("IsCheckCode"));
}else {return null;}
}catch(SQLException e){System.out.println(e.getMessage());return null;}
finally{
try{
if(rs!=null){rs.close();}
if(ps!=null){ps.close();}
if(conn!=null){conn.close();}
}catch(SQLException e1){System.out.println(e1.getMessage());}}
return ht;
}
public static void main(String args[])
{
SingleRecordModel srm=new SingleRecordModel();
if(srm.NewsRecord("2")!=null)
System.out.println("OK");
else System.out.println("failure");
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -