数据库MySQL与java结合学习

今天学的东西很多,数据多层次的运用连接java编译器:

数据表示层:

package com.lifeng.test;

import java.sql.Connection;

import java.sql.PreparedStatement;

import java.sql.ResultSet;

import java.text.SimpleDateFormat;

import java.util.Date;

import java.util.List;

import java.util.Scanner;

import com.lifeng.dao.Dao;

import com.lifeng.dao.EmpDao;

import com.lifeng.dao.EmpDao02;

import com.lifeng.dao.EmpDao03;

import com.lifeng.dao.EmpDao04;

import com.lifeng.entity.Employee;

import com.lifeng.entity.User;

public class TestEmpDao {

public static void main(String[] args) {

//ShowAllEmp();

//SelectSingleEmp();

UserLogin();

//AddEmp();}

static EmpDao03 empDao03 = new EmpDao03();

private static void AddEmp() {

try {

Employee emp = new Employee();

Scanner input = new Scanner(System.in);

System.out.print("请输入员工编号:");

int empno=input.nextInt();

System.out.print("请输入员工姓名:");

String ename=input.next();

System.out.print("请输入员工 职位:");

String job=input.next();

System.out.print("请输入上司编号:");

int mgr=input.nextInt();

System.out.print("请输入入职日期(yyyy-MM-dd):");

String date=input.next();

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

Date hiredate = sdf.parse(date);

System.out.print("请输入基本工资:");

double sal=input.nextDouble();

System.out.print("请输入奖金:");

double comm=input.nextDouble();

System.out.print("请输入部门编号(10,20,30):");

int deptno=input.nextInt();

emp.setEmpno(empno);

emp.setEname(ename);

emp.setJob(job);

emp.setMgr(mgr);

emp.setHiredate(hiredate);

emp.setSal(sal);

emp.setComm(comm);

emp.setDeptno(deptno);

int count = empDao03.addEmp(emp);

if(count > 0) {

System.out.println("员工添加成功!");

System.out.println("如需返回系统界面请按0");

int sc = input.nextInt();

if(sc == 0) {

UserWelcome();

}else {

System.out.println("系统已为你返回界面");

UserWelcome();}

}else {

System.out.println("员工添加错失败!");}

} catch (Exception e) {

e.printStackTrace();}}

static Dao  dao = new Dao();

private static void UserLogin() {

Scanner input = new Scanner(System.in);

System.out.println("请输入用户名:");

String username = input.next();

System.out.println("请输入用户密码:");

String pwd = input.next();

User user = dao.FindUserByNamePwd(username, pwd);

if(user != null) {

System.out.println("登陆成功");

UserWelcome();}else {

System.out.println("登陆失败");}}

static EmpDao04 empDao04 = new EmpDao04();

public static void UserWelcome() {

System.out.println("=========员工管理系统项目=========");

System.out.println("请选择操作:");

System.out.println("1.查询所有员工");

System.out.println("2.查询单个员工");

System.out.println("3.添加员工");

System.out.println("4.删除员工");

System.out.println("5.修改员工");

Scanner sc = new Scanner(System.in);

int input = sc.nextInt();

switch(input) {

case 1:

ShowAllEmp();//查询所有员工

break;

case 2:

SelectSingleEmp();//查询单个员工

break;

case 3:

AddEmp();//添加员工

break;

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值