日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > 数据库 >内容正文

数据库

mysql 网页员工登记表_作业1:小型考勤登记表

發布時間:2023/12/14 数据库 31 豆豆
生活随笔 收集整理的這篇文章主要介紹了 mysql 网页员工登记表_作业1:小型考勤登记表 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

這次在廣州實習了20天,收獲還比較大。不過仍需要繼續努力。這次總共布置了兩個作業,我總結一下:

登記考勤信息,查看信息——主要就是往數據庫增加數據,然后再從數據庫中讀取出來。

代碼演示:

從數據庫里面寫入數據:

String name= request.getParameter("name");

String dept= request.getParameter("dept");

String datetime= request.getParameter("datetime");

SimpleDateFormat sdf= new SimpleDateFormat("yyyy-mm-dd");

Date date=sdf.parse(datetime);int status =Integer.valueOf(request.getParameter("status")).intValue();

attence a= newattence();

a.setEmpName(name);

a.setDept(dept);

a.setDatetime(date);

a.setStatus(status);

AttenceBiz attenceBiz= newAttenceBizImpl();boolean result =attenceBiz.addAttence(a);if(result){//response.sendRedirect("index.jsp");

out.print("成功");

}else{//request.getRequestDispatcher("add.jsp").forward(request, response);

out.print("失敗");

}%>

這個是在jsp里面寫的,不是在servlet里面寫的。因為好理解,不過我現在已經習慣了寫在servlet里面了。

首頁jsp,往里面寫入數據:

String basePath= request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";%>

考勤記錄信息統計考勤記錄信息統計表姓名所屬部門考勤日期考勤狀態

正常

遲到

早退

休假

外出

查看所有考勤信息

獲取所有數據的jsp:

List attences =aBiz.getAll();

request.setAttribute("attences", attences);%>

考勤記錄信息統計考勤記錄信息統計表員工姓名所屬部門考勤日期考勤狀態
${attence.empName }${attence.dept }${attence.datetime }${attence.status }

這個是把數據庫里面的數據全部讀取出來。

主要的方法實現:

packagecom.Attence.daoImpl;importjava.sql.ResultSet;importjava.sql.SQLException;importjava.util.ArrayList;importjava.util.List;importcom.Attence.dao.AttenceDao;importcom.Seraphjin.Attence.model.attence;public class AttenceDaoImpl extends BaseDao implementsAttenceDao {

ArrayList attences = new ArrayList();

@Overridepublic ListgetAll() {try{

openConnection();

String sql= "select * from attence";

ResultSet resultSet= executeQuery(sql, null);while(resultSet.next()) {

attence a= newattence();

a.setId(resultSet.getInt("id"));

a.setEmpName(resultSet.getString("empName"));

a.setDept(resultSet.getString("dept"));

a.setDatetime(resultSet.getDate("datetime"));

a.setStatus(resultSet.getInt("status"));

attences.add(a);

}

}catch(ClassNotFoundException e) {

e.printStackTrace();

}catch(SQLException e) {

e.printStackTrace();

}finally{

closeResourse();

}returnattences;

}

@Overridepublic booleanaddAttence(attence a) {boolean result = false;try{

openConnection();

String sql="insert into attence value(?,?,?,?,?)";

result=excute(sql, newObject[]{

a.getId(),

a.getEmpName(),

a.getDept(),

a.getDatetime(),

a.getStatus()

});

}catch(ClassNotFoundException e) {

e.printStackTrace();

}catch(SQLException e) {

e.printStackTrace();

}finally{

closeResourse();

}returnresult;

}

@Overridepublic boolean deleteAttence(intid) {boolean result = false;try{

openConnection();

String sql="delete from attence where id = ?";

result= excute(sql, newObject[]{id});

}catch(ClassNotFoundException e) {

e.printStackTrace();

}catch(SQLException e) {

e.printStackTrace();

}finally{

closeResourse();

}returnresult;

}

@Overridepublic booleanupdateAttence(attence a) {boolean result = false;try{

openConnection();

String sql= "update attence set empName = ?, dept =?, datetime=?,status=? where id=?";

result= excute(sql, newObject[]{

a.getId()

});

}catch(ClassNotFoundException e) {

e.printStackTrace();

}catch(SQLException e) {

e.printStackTrace();

}finally{

closeResourse();

}returnresult;

}

}

連接數據庫的基本操作:

packagecom.Attence.daoImpl;importjava.sql.Connection;importjava.sql.DriverManager;importjava.sql.PreparedStatement;importjava.sql.ResultSet;importjava.sql.SQLException;public classBaseDao {//連接數據庫

private String className = "com.mysql.jdbc.Driver";private String dburl = "jdbc:mysql://localhost/ZJJexe";private String user = "root";private String password = "root";privateConnection connection;privatePreparedStatement statement;privateResultSet resultSet;public void openConnection() throwsClassNotFoundException, SQLException{//加載驅動

Class.forName(className);//創建連接

connection =DriverManager.getConnection(dburl,user,password);

}//查詢方法

public ResultSet executeQuery(String sql,Object[] params) throwsSQLException{

statement=connection.prepareStatement(sql);//追加參數

if(params !=null){int i=1;for(Object object : params) {

statement.setObject(i, object);

i++;

}

}

resultSet=statement.executeQuery();returnresultSet;

}//更新

public boolean excute(String sql,Object[] params) throwsSQLException {

statement=connection.prepareStatement(sql);if(params !=null){int i=1;for(Object object : params) {

statement.setObject(i, object);

i++;

}

}int updateCount =statement.executeUpdate();if (updateCount != 0) {return true;

}else{return false;

}

}//釋放資源

public voidcloseResourse(){try{if(resultSet != null){

resultSet.close();

}if(statement != null){

statement.close();

}if(connection != null){

connection.close();

}

}catch(SQLException e) {//TODO Auto-generated catch block

e.printStackTrace();

}

}

}

其他就是方法的聲明與調用。還有一個實體類,是員工信息:

packagecom.Seraphjin.Attence.model;importjava.util.Date;public classattence {private intid;privateString empName;privateString dept;privateDate datetime;private intstatus;public intgetId() {returnid;

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

}publicString getEmpName() {returnempName;

}public voidsetEmpName(String empName) {this.empName =empName;

}publicString getDept() {returndept;

}public voidsetDept(String dept) {this.dept =dept;

}publicDate getDatetime() {returndatetime;

}public voidsetDatetime(Date datetime) {this.datetime =datetime;

}public intgetStatus() {returnstatus;

}public void setStatus(intstatus) {this.status =status;

}

}

OK~

近期我要學會用小烏龜,然后將自己的小項目部署到Github上~加油!

總結

以上是生活随笔為你收集整理的mysql 网页员工登记表_作业1:小型考勤登记表的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。