?? affichedao.java
字號(hào):
package com.wy.dao;
import java.sql.*;
import java.util.*;
import com.wy.tool.JDBConnection;
import com.wy.domain.AfficheForm;
//對(duì)公告信息的操作
public class AfficheDao {
private Connection connection = null; //定義連接的對(duì)象
private PreparedStatement ps = null; //定義預(yù)準(zhǔn)備的對(duì)象
private JDBConnection jdbc = null; //定義數(shù)據(jù)庫(kù)連接對(duì)象
public AfficheDao() {
jdbc = new JDBConnection();
connection = jdbc.connection; //利用構(gòu)造方法取得數(shù)據(jù)庫(kù)連接
}
//刪除的方法
public void deleteAffiche(Integer id) {
try {
ps = connection.prepareStatement("delete from tb_affiche where id=?");
ps.setInt(1, id.intValue());
ps.executeUpdate();
ps.close();
}
catch (SQLException ex) {
}
}
//修改的方法
public void updateAffiche(AfficheForm form) {
try {
ps = connection.prepareStatement("update tb_affiche set name=?,content=? where id=?");
ps.setString(1, form.getName());
ps.setString(2, form.getContent());
ps.setInt(3, form.getId().intValue());
ps.executeUpdate();
ps.close();
}
catch (SQLException ex) {
}
}
//添加的方法
public void insertAffiche(AfficheForm form) {
try {
ps = connection.prepareStatement("insert into tb_affiche values (?,?,getDate())");
ps.setString(1, form.getName());
ps.setString(2, form.getContent());
ps.executeUpdate();
ps.close();
}
catch (SQLException ex) {
}
}
//以數(shù)據(jù)庫(kù)流水號(hào)為條件查詢信息
public AfficheForm selectOneAffiche(Integer id) {
AfficheForm affiche = null;
try {
ps = connection.prepareStatement("select * from tb_affiche where id=?");
ps.setInt(1, id.intValue());
ResultSet rs = ps.executeQuery();
while (rs.next()) {
affiche = new AfficheForm();
affiche.setId(Integer.valueOf(rs.getString(1)));
affiche.setName(rs.getString(2));
affiche.setContent(rs.getString(3));
affiche.setIssueTime(rs.getString(4));
}
}
catch (SQLException ex) {
}
return affiche;
}
//全部查詢的方法
public List selectAffiche() {
List list = new ArrayList();
AfficheForm affiche = null;
try {
ps = connection.prepareStatement("select * from tb_affiche order by id DESC");
ResultSet rs = ps.executeQuery();
while (rs.next()) {
affiche = new AfficheForm();
affiche.setId(Integer.valueOf(rs.getString(1)));
affiche.setName(rs.getString(2));
affiche.setContent(rs.getString(3));
affiche.setIssueTime(rs.getString(4));
list.add(affiche);
}
}
catch (SQLException ex) {
}
return list;
}
}
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -