notice.java~33~
来自「用户的注册 用户的登陆 发布用户的相关信息 浏览网站介绍的其他酒店的」· JAVA~33~ 代码 · 共 263 行
JAVA~33~
263 行
package dao;
import domain.NoticeForm;
import tool.Conn;
import tool.SQLCode;
import java.sql.Statement;
import java.sql.ResultSet;
import java.sql.Connection;
import tool.EidetSql;
import java.sql.*;
import java.util.Collection;
import java.util.ArrayList;
public class Notice implements NoticeDao {
EidetSql ed = new EidetSql();
public Notice() {
}
/*******************************************
* method name:insert
* method function :插入一条公告
* return type:int
* datetime : 2007-09-17
*******************************************/
public int insert(NoticeForm notic) {
Connection con = null;
Statement st = null;
ResultSet rs = null;
Conn cn = new Conn();
SQLCode sc = new SQLCode();
String sql = sc.getSQLCode("sql.notice.insert");
sql = ed.editSqlStr(sql, notic.getNotice_title());
sql = ed.editSqlStr(sql, notic.getNotice_content());
int row = 0;
try {
con = cn.getConnection();
st = con.createStatement();
row = st.executeUpdate(sql);
if (st != null) {
st.close();
}
if (con != null) {
con.close();
}
} catch (SQLException ex) {
System.out.println("插入公告sql:" + ex.getMessage());
} catch (ClassNotFoundException ex) {
System.out.println("类加载:" + ex.getMessage());
}
return row;
}
/*******************************************
* method name:delect
* method function :删除公告
* return type:int
* datetime : 2007-09-17
*******************************************/
public int delect(NoticeForm notic) {
Connection con = null;
Statement st = null;
ResultSet rs = null;
Conn cn = new Conn();
SQLCode sc = new SQLCode();
String sql = sc.getSQLCode("sql.notice.delete");
sql = ed.editSqlInt(sql, notic.getNotice_id());
int row = 0;
try {
con = cn.getConnection();
st = con.createStatement();
row = st.executeUpdate(sql);
if (st != null) {
st.close();
}
if (con != null) {
con.close();
}
} catch (SQLException ex) {
System.out.println("删除公告sql:" + ex.getMessage());
} catch (ClassNotFoundException ex) {
System.out.println("类加载:" + ex.getMessage());
}
return row;
}
/*******************************************
* method name:select
* method function :查询公告信息
* return type:int
* datetime : 2007-09-17
*******************************************/
public Collection select(NoticeForm notic, int page) {
Connection con = null;
Statement st = null;
ResultSet rs = null;
Conn cn = new Conn();
SQLCode sc = new SQLCode();
String sql = sc.getSQLCode("sql.notice.select");
Collection list = new ArrayList();
try {
con = cn.getConnection();
st = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
ResultSet.CONCUR_READ_ONLY);
rs = st.executeQuery(sql);
int tip = 6 * (page - 1);
try {
if (tip <= 0) {
rs.beforeFirst();
} else {
if (!rs.absolute(tip)) {
rs.beforeFirst();
}
}
} catch (SQLException ex1) {
System.out.println("tip" + ex1.getMessage());
}
for (int i = 1; rs.next() && i <= 6; i++) {
notic = new NoticeForm();
notic.setNotice_id(rs.getInt(1));
notic.setNotice_title(rs.getString(2));
notic.setNotice_content(rs.getString(3));
notic.setNotice_time(rs.getString(4));
list.add(notic);
}
if (rs != null) {
rs.close();
}
if (st != null) {
st.close();
}
if (con != null) {
con.close();
}
} catch (SQLException ex) {
System.out.println("查询公告sql:" + ex.getMessage());
} catch (ClassNotFoundException ex) {
System.out.println("类加载:" + ex.getMessage());
}
return list;
}
/*******************************************
* method name:update
* method function :更新公告信息
* return type:int
* datetime : 2007-09-17
*******************************************/
public int update(NoticeForm notic) {
Connection con = null;
Statement st = null;
ResultSet rs = null;
Conn cn = new Conn();
SQLCode sc = new SQLCode();
String sql = sc.getSQLCode("sql.notice.update");
sql = ed.editSqlStr(sql, notic.getNotice_title());
sql = ed.editSqlStr(sql, notic.getNotice_content());
sql = ed.editSqlStr(sql, notic.getNotice_time());
sql = ed.editSqlInt(sql, notic.getNotice_id());
int row = 0;
try {
con = cn.getConnection();
st = con.createStatement();
row = st.executeUpdate(sql);
if (st != null) {
st.close();
}
if (con != null) {
con.close();
}
} catch (SQLException ex) {
System.out.println("更新公告sql:" + ex.getMessage());
} catch (ClassNotFoundException ex) {
System.out.println("类加载:" + ex.getMessage());
}
return row;
}
/*******************************************
* method name:count
* method function :统计公告信息
* return type:int
* datetime : 2007-09-17
*******************************************/
public int count() {
Connection con = null;
Statement st = null;
ResultSet rs = null;
Conn cn = new Conn();
SQLCode sc = new SQLCode();
String sql = sc.getSQLCode("sql.notice.count");
int row = 0;
try {
con = cn.getConnection();
st = con.createStatement();
rs = st.executeQuery(sql);
if (rs.next()) {
row = rs.getInt(1);
}
} catch (SQLException ex) {
System.out.println("统计公告信息sql:" + ex.getMessage());
} catch (ClassNotFoundException ex) {
System.out.println("类加载:" + ex.getMessage());
}
return row;
}
/*******************************************
* method name:selectNotice
* method function :查询公告信息
* return type:int
* datetime : 2007-09-17
*******************************************/
public Collection selectNotice(NoticeForm notic) {
Connection con = null;
Statement st = null;
ResultSet rs = null;
Conn cn = new Conn();
SQLCode sc = new SQLCode();
String sql = sc.getSQLCode("sql.notice.selectNotice");
Collection list = new ArrayList();
try {
con = cn.getConnection();
st = con.createStatement();
rs = st.executeQuery(sql);
while(rs.next()) {
notic = new NoticeForm();
notic.setNotice_id(rs.getInt(1));
notic.setNotice_title(rs.getString(2));
notic.setNotice_content(rs.getString(3));
notic.setNotice_time(rs.getString(4));
list.add(notic);
}
if (rs != null) {
rs.close();
}
if (st != null) {
st.close();
}
if (con != null) {
con.close();
}
} catch (SQLException ex) {
System.out.println("查询公告sql:" + ex.getMessage());
} catch (ClassNotFoundException ex) {
System.out.println("类加载:" + ex.getMessage());
}
return list;
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?