资源简介
springMVC入门实例,对员工增删改查操作,员工关联部门,代码简单易懂。(员工系统-Mysql)
代码片段和文件信息
package com.jdbc;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import com.springemployee.crud.entities.Employee;
public class JDBC {
PreparedStatement ps;
ResultSet rs;
//写一个连接数据库的方法
private static Connection getConnection(){
String url=“jdbc:mysql://localhost:3306/emp“;
String userName=“root“;
String password=“123456“;
Connection conn=null;
try{
Class.forName(“com.mysql.jdbc.Driver“);
}catch(ClassNotFoundException e){
System.out.println(“找不到驱动!“);
e.printStackTrace();
}
try{
conn=DriverManager.getConnection(urluserNamepassword);
if(conn!=null){
System.out.println(“connection successful“);
}
}catch(SQLException e){
System.out.println(“connection fail“);
e.printStackTrace();
}
return conn;
}
//写一个查询数据库语句的方法
public static int insert(Employee employee) {
Connection conn = getConnection();
int i = 0;
String sql = “insert into Employee (lastNameemailgenderdepartment) values(????)“;
PreparedStatement pstmt;
try {
pstmt = (PreparedStatement) conn.prepareStatement(sql);
pstmt.setString(1 employee.getLastName());
pstmt.setString(2 employee.getEmail());
pstmt.setInt(3 employee.getGender());
pstmt.setInt(4 employee.getDepartment());
pstmt.execute();
pstmt.close();
conn.close();
} catch (SQLException e) {
e.printStackTrace();
}
return i;
}
public static int update(Employee employee) {
Connection conn = getConnection();
int i = 0;
String sql = “update Employee set lastName=‘“+employee.getLastName()+“‘ email=‘“+employee.getEmail()+“‘ gender=“+employee.getGender()+“ department=“+employee.getDepartment()+“ where id=“ +employee.getId();
PreparedStatement pstmt;
try {
pstmt = (PreparedStatement) conn.prepareStatement(sql);
i = pstmt.executeUpdate();
System.out.println(“resutl: “ + i);
pstmt.close();
conn.close();
} catch (SQLException e) {
e.printStackTrace();
}
return i;
}
public static List getAll() {
Connection conn = getConnection();
List list=new ArrayList();
String sql = “select * from Employee“;
PreparedStatement pstmt;
try {
pstmt = (PreparedStatement)conn.prepareStatement(sql);
ResultSet rs = pstmt.executeQuery();
// int col = rs.getmetaData().getColumnCount();
System.out.println(“=
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2017-03-23 16:01 springemployee\
文件 898 2017-03-21 14:18 springemployee\.classpath
文件 1122 2017-03-16 10:22 springemployee\.project
目录 0 2017-03-16 11:58 springemployee\.settings\
文件 567 2017-03-16 10:11 springemployee\.settings\.jsdtscope
文件 122 2017-03-22 19:10 springemployee\.settings\org.eclipse.core.resources.prefs
文件 364 2017-03-16 10:11 springemployee\.settings\org.eclipse.jdt.core.prefs
文件 494 2017-03-16 10:11 springemployee\.settings\org.eclipse.wst.common.component
文件 349 2017-03-16 10:11 springemployee\.settings\org.eclipse.wst.common.project.facet.core.xm
文件 49 2017-03-16 10:11 springemployee\.settings\org.eclipse.wst.jsdt.ui.superType.container
文件 6 2017-03-16 10:11 springemployee\.settings\org.eclipse.wst.jsdt.ui.superType.name
文件 455 2017-03-16 10:22 springemployee\.springBeans
目录 0 2017-03-16 10:11 springemployee\build\
目录 0 2017-03-25 09:41 springemployee\build\classes\
目录 0 2017-03-25 09:41 springemployee\build\classes\com\
目录 0 2017-03-25 09:41 springemployee\build\classes\com\jdbc\
文件 5260 2017-03-25 09:41 springemployee\build\classes\com\jdbc\JDBC.class
文件 4898 2017-03-25 09:41 springemployee\build\classes\com\jdbc\JdbcUtil.class
目录 0 2017-03-25 09:41 springemployee\build\classes\com\springemployee\
目录 0 2017-03-25 09:41 springemployee\build\classes\com\springemployee\crud\
目录 0 2017-03-25 09:41 springemployee\build\classes\com\springemployee\crud\dao\
文件 1567 2017-03-25 09:41 springemployee\build\classes\com\springemployee\crud\dao\DepartmentDao.class
文件 1417 2017-03-25 09:41 springemployee\build\classes\com\springemployee\crud\dao\EmployeeDao.class
目录 0 2017-03-25 09:41 springemployee\build\classes\com\springemployee\crud\entities\
文件 1405 2017-03-25 09:41 springemployee\build\classes\com\springemployee\crud\entities\Department.class
文件 2226 2017-03-25 09:41 springemployee\build\classes\com\springemployee\crud\entities\Employee.class
目录 0 2017-03-25 09:41 springemployee\build\classes\com\springemployee\crud\handlers\
文件 3512 2017-03-25 09:41 springemployee\build\classes\com\springemployee\crud\handlers\EmployeeHandler.class
文件 3524 2017-03-25 09:41 springemployee\build\classes\com\springemployee\crud\handlers\JdbcTest.class
文件 1165 2017-03-20 10:03 springemployee\build\classes\springmvc.xm
文件 857 2017-03-25 09:45 springemployee\emp.sql
............此处省略59个文件信息
相关资源
- 基于SSM框架的完整项目 Spring+SpringMV
- 家庭财务管理系统SpringMVC3+Spring3+Myb
- springmvc+jdbctemplate+mysql(采用注解方式
- spring+Mybatis+SpringMVC资源整合增删改查
- maven+springMVC+mybatis+mysql+Bootstrap-Admin-
- SpringMVC+Mysql详解
- 基于springmvc+mybatis+spring+maven+mysql的网
- spring+springmvc+mybatis完善的增删改查,
- 网上书店SSM+Bootstrap+Mysql
- 基于Spring MVC+Spring+Mybatis+Mysql 客户关
- 毕业设计:教学评教系统.rar
- spring+springmvc+mybatis搭建的一个华仪酒
- eclipse(springmvc+spring+hibernate)案例附
- 基于SpringMVC的学生成绩管理
- SSH企业网站源码
- SpringMVC4+Spring4+Hibernate4框架整合
- spring+springmvc+mybatis搭建的一个佳期酒
- spring+springmvc+mybatis搭建的一个酒店管
- spring+springmvc+mybatis搭建的一个典当系
- SSM客户管理系统(包含SQL脚本)
- http接口返回json,springmvc+mybatis+oracl
- springmvc写的超市订单管理系统
- 基于Springmvc、mybaits的简单课程设计购
- 留言板基于springmvc+js+jq+ajax+oracle开发
- SpringMVC+Hibernate+Spring毕业设计完整OA源
- SpringMVC+mysql+idea+JDBC实现的登陆注册系
- spring+springmvc+mybatis搭建的一个美康医
- SpringMVC+Spring+mybatis+Mysql 客户关系管理
- ERP采购系统
- springmvc+mybatis+sqlserver小
评论
共有 条评论