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

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 运维知识 > 数据库 >内容正文

数据库

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

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

這次在廣州實(shí)習(xí)了20天,收獲還比較大。不過(guò)仍需要繼續(xù)努力。這次總共布置了兩個(gè)作業(yè),我總結(jié)一下:

登記考勤信息,查看信息——主要就是往數(shù)據(jù)庫(kù)增加數(shù)據(jù),然后再?gòu)臄?shù)據(jù)庫(kù)中讀取出來(lái)。

代碼演示:

從數(shù)據(jù)庫(kù)里面寫入數(shù)據(jù):

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("失敗");

}%>

這個(gè)是在jsp里面寫的,不是在servlet里面寫的。因?yàn)楹美斫?#xff0c;不過(guò)我現(xiàn)在已經(jīng)習(xí)慣了寫在servlet里面了。

首頁(yè)jsp,往里面寫入數(shù)據(jù):

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

考勤記錄信息統(tǒng)計(jì)考勤記錄信息統(tǒng)計(jì)表姓名所屬部門考勤日期考勤狀態(tài)

正常

遲到

早退

休假

外出

查看所有考勤信息

獲取所有數(shù)據(jù)的jsp:

List attences =aBiz.getAll();

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

考勤記錄信息統(tǒng)計(jì)考勤記錄信息統(tǒng)計(jì)表員工姓名所屬部門考勤日期考勤狀態(tài)
${attence.empName }${attence.dept }${attence.datetime }${attence.status }

這個(gè)是把數(shù)據(jù)庫(kù)里面的數(shù)據(jù)全部讀取出來(lái)。

主要的方法實(shí)現(xiàn):

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;

}

}

連接數(shù)據(jù)庫(kù)的基本操作:

packagecom.Attence.daoImpl;importjava.sql.Connection;importjava.sql.DriverManager;importjava.sql.PreparedStatement;importjava.sql.ResultSet;importjava.sql.SQLException;public classBaseDao {//連接數(shù)據(jù)庫(kù)

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{//加載驅(qū)動(dòng)

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

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

}//查詢方法

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

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

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();

}

}

}

其他就是方法的聲明與調(diào)用。還有一個(gè)實(shí)體類,是員工信息:

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~

近期我要學(xué)會(huì)用小烏龜,然后將自己的小項(xiàng)目部署到Github上~加油!

總結(jié)

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

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。