⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 userbean.java~1~

📁 Jsf写的增删改查 Jsf写的增删改查
💻 JAVA~1~
字号:
package com.accp;

import java.sql.*;
import java.util.*;
import javax.faces.context.*;
import javax.faces.model.*;
import javax.servlet.jsp.jstl.sql.*;

public class UserBean {
  private String sex;
  private String userName;
  private String passWord;
  private SelectItem[] sexs = new SelectItem[]{
      new SelectItem("famle","famle"),
      new SelectItem("male","male"),
      new SelectItem("laochen","laochen")
  };
  private String chapterdetail = "";
  private String chaptermaster = "";
  private String chapter = "";
  private String id;

  public Collection getAlll()
  {
    Collection coll = new ArrayList();
    String sql  = "select * from chapter";
    BaseDao db = new BaseDao();
    try
    {
    ResultSet rs = db.executeQuery(sql);
    while(rs.next())
    {
      ChapterForm form = new ChapterForm();
      form.setId(rs.getString(1));
      form.setChapter(rs.getString(2));
      form.setChapterdetail(rs.getString(3));
      form.setChaptermaster(rs.getString(4));
      coll.add(form);
    }
    }catch(Exception ex)
    {
      System.out.println(ex);
    }finally
    {
      db.close();
    }
    return coll;
  }

  public String add()
  {
    String sql  = "insert into chapter(chapter,chapterdetail,chaptermaster) values('"+this.getChapter()+"','"+this.getChapterdetail()+"','"+this.getChaptermaster()+"')";
    BaseDao db = new BaseDao();
    try {
      db.executeUpdate(sql);
    }
    catch (SQLException ex) {
    }finally
    {
      db.close();
    }
    return "list";
  }

  public String show()
  {
    FacesContext ctx = FacesContext.getCurrentInstance();
    String ID = (String)ctx.getExternalContext().getRequestParameterMap().get("ID");
    String sql = "select * from chapter where ID="+ID;
    System.out.println("aaaaaaaaaaaaaa"+sql);
    BaseDao db = new BaseDao();
    try {
      ResultSet rs = db.executeQuery(sql);
      if(rs.next())
      {
        this.setId(rs.getString(1));
        this.setChapter(rs.getString(2));
        this.setChapterdetail(rs.getString(3));
        this.setChaptermaster(rs.getString(4));
        System.out.println(this.getId());
      }
    }
    catch (SQLException ex) {
    }finally
    {
      db.close();
    }
    return "update";
  }

  public String update()
  {
    System.out.println(this.getId());
    String sql = "update chapter set chapter = '"+this.getChapter()+"',chapterdetail='"+this.getChapterdetail()+"',chaptermaster='"+this.getChaptermaster()+ "' where ID="+this.getId();
    BaseDao db = new BaseDao();
    try {
      db.executeUpdate(sql);
    }
    catch (SQLException ex) {
    }finally
    {
      db.close();
    }
    return "list";
  }

  public String delete()
  {
    FacesContext ctx = FacesContext.getCurrentInstance();
    String ID = (String)ctx.getExternalContext().getRequestParameterMap().get("ID");
    String sql = "delete from chapter where ID="+ID;
    BaseDao db = new BaseDao();
    try {
      db.executeUpdate(sql);
    }
    catch (SQLException ex) {
    }finally
    {
      db.close();
    }
    return "list";
  }

  public Result getAll()
  {
    String sql  = "select * from chapter";
    BaseDao db = new BaseDao();
    try {
      ResultSet rs = db.executeQuery(sql);
      return ResultSupport.toResult(rs);
    }
    catch (SQLException ex) {
    }finally
    {
      db.close();
    }
    return null;
  }

  public void setSexs(SelectItem[] sexs)
  {
    this.sexs = sexs;
  }

  public SelectItem[] getSexs()
  {
    return this.sexs;
  }

  public UserBean() {
  }

  public void setSex(String sex) {
    this.sex = sex;
  }

  public void setUserName(String userName) {
    this.userName = userName;
  }

  public void setPassWord(String passWord) {
    this.passWord = passWord;
  }

  public void setChapterdetail(String chapterdetail) {
    this.chapterdetail = chapterdetail;
  }

  public void setChaptermaster(String chaptermaster) {
    this.chaptermaster = chaptermaster;
  }

  public void setChapter(String chapter) {
    this.chapter = chapter;
  }

  public void setId(String id) {
    this.id = id;
  }

  public String getSex() {
    return sex;
  }

  public String getUserName() {
    return userName;
  }

  public String getPassWord() {
    return passWord;
  }

  public String getChapterdetail() {
    return chapterdetail;
  }

  public String getChaptermaster() {
    return chaptermaster;
  }

  public String getChapter() {
    return chapter;
  }

  public String getId() {
    return id;
  }

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -