📄 notedaoimpl.java
字号:
package zd.bbs.view ;
import zd.bbs.*;
//ע���¼ģ��
import java.sql.* ;
import java.util.* ;
import zd.bbs.view.*;
public class NoteDAOImpl implements NoteDAO
{
public int countPerPage = 5; //ÿҳ��ʾ����
public List query_view() throws Exception
{
List all_view = new ArrayList() ;
String sql = "select * from model_1" ;
PreparedStatement pstmt = null ;
DataBaseConnection dbc = null ;
dbc = new DataBaseConnection() ;
try
{
pstmt = dbc.getConnection().prepareStatement(sql) ;
ResultSet rs = pstmt.executeQuery() ;
while(rs.next())
{
Note note = new Note() ;
note.setModel_id(rs.getInt("model_id"));
note.setModel_name(rs.getString("model_name"));
all_view.add(note) ;
}
rs.close() ;
pstmt.close() ;
}
catch (Exception e)
{}
finally
{
dbc.close() ;
}
return all_view ;
}
public List query_view1(int lid) throws Exception
{
List all_view1 = new ArrayList() ;
String sql = "select model_id2,model_name2,model_ms2 from model_2 where model_id='"+lid+"' group by model_id2,model_name2,model_ms2 " ;
// String sql = "select talk.model_id2,model_name2,model_ms2,count(talk.model_id2) as ztcount from model_2,talk where model_2.model_id2=talk.model_id2 and model_id='"+lid+"' group by talk.model_id2,model_name2,model_ms2 " ;
//String sql="SELECT talk.model_id2,model_id2,model_name2,model_ms2,count(talk.model_id2) as ztcount FROM model_2,talk where model_2.model_id2=talk.model_id2='"+lid+"'";
PreparedStatement pstmt = null ;
DataBaseConnection dbc = null ;
dbc = new DataBaseConnection() ;
try
{
pstmt = dbc.getConnection().prepareStatement(sql) ;
ResultSet rs = pstmt.executeQuery() ;
while(rs.next())
{
Note note = new Note() ;
note.setModel_id2(rs.getInt("model_id2"));
note.setModel_name2(rs.getString("model_name2"));
note.setModel_ms2(rs.getString("model_ms2"));
//note.setZtcount(rs.getInt("ztcount"));
all_view1.add(note) ;
}
rs.close() ;
pstmt.close() ;
}
catch (Exception e)
{
}
finally
{
dbc.close() ;
}
return all_view1 ;
}
public List query_content(int cid) throws Exception
{
List all_view = new ArrayList() ;
String sql = "select * from talk,zu where talk.username=zu.username and talk_id='"+cid+"'";
PreparedStatement pstmt = null ;
DataBaseConnection dbc = null ;
dbc = new DataBaseConnection() ;
try
{
pstmt = dbc.getConnection().prepareStatement(sql) ;
ResultSet rs = pstmt.executeQuery() ;
while(rs.next())
{
Note note = new Note() ;
note.setUsername(rs.getString("username"));
note.setTitle(rs.getString("title"));
note.setTalk_content(rs.getString("talk_content"));
note.setTag(rs.getString("tag"));
note.setData_time(rs.getString("data_time"));
note.setTalk_face(rs.getString("talk_face"));
note.setPhoto_up(rs.getString("photo_up"));
note.setPhoto_sm(rs.getString("photo_sm"));
all_view.add(note) ;
}
rs.close() ;
pstmt.close() ;
}
catch (Exception e)
{
}
finally
{
dbc.close() ;
}
return all_view ;
}
//��ѯ�ظ������ݷ�ҳ��ʾ
public List query_answer(int cid,int nowPages) throws Exception
{
List all_view_answer = new ArrayList() ;
//String sql = "select top "+countPerPage+" * from talk where model_id2='"+lid+"' and talk_id not in (select top "+(nowPages-1)* countPerPage+" talk_id from talk where model_id2='"+lid+"' order by talk_id desc )order by talk_id desc";
String sql="select top "+countPerPage+" * from answer,zu where answer.username=zu.username and talk_id='"+cid+"' and answer_id not in(select top "+(nowPages-1)* countPerPage+" answer_id from answer where talk_id='"+cid+"' order by answer_id desc)order by answer_id desc";
//String sql = "select top 5 * from answer,zu where answer.username=zu.username and talk_id='"+cid+"' not in(select top 5 answer_id from answer,zu where answer.username=zu.username and talk_id='"+cid+"' order by answer_id desc )order by answer_id desc";
PreparedStatement pstmt = null ;
DataBaseConnection dbc = null ;
dbc = new DataBaseConnection() ;
try
{
pstmt = dbc.getConnection().prepareStatement(sql) ;
ResultSet rs = pstmt.executeQuery() ;
while(rs.next())
{
Note note = new Note() ;
note.setUsername(rs.getString("username"));
note.setTag(rs.getString("tag"));
note.setAnswer_content(rs.getString("answer_content"));
note.setPhoto_up(rs.getString("photo_up"));
note.setData_time(rs.getString("data_time"));
note.setAnswer_id(rs.getInt("answer_id"));
all_view_answer.add(note) ;
}
rs.close() ;
pstmt.close() ;
}
catch (Exception e)
{
}
finally
{
dbc.close() ;
}
return all_view_answer ;
}
public boolean check(String photo_up){
boolean flag = true;
int ph = photo_up.lastIndexOf(".");
String p = photo_up.substring(ph + 1);
String s1 = "JPG|jpg|bmp|dib|gif|png|rle|tif|tiff|bw|cdr|col|dwg|dxb|dxf|wmf|emf|eps|ico|iff|jpeg|lbm|mag|mac|mpt|msk|opt|ply|"
+ "pbm|pgm|ppm|pcd|pcx|pic|pict|pict2|pnt|psd|pxr|ras|raw|tga|win|xbm|GIF";
String ss = s1.replace(p, "***");
if (ss == "JPG|jpg|bmp|dib|gif|png|rle|tif|tiff|bw|cdr|col|dwg|dxb|dxf|wmf|emf|eps|ico|iff|jpeg|lbm|mag|mac|mpt|msk|opt|ply|pbm|pgm|ppm|pcd|pcx|pic|pict|pict2|pnt|psd|pxr|ras|raw|tga|win|xbm|GIF") {
flag = false;
}
return flag;
}
};
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -