所用jar包

commons-beanutils-1.8.0.jar
commons-logging-1.1.3.jar
druid-1.0.9.jar
mysql-connector-java-5.1.18-bin.jar
spring-beans-3.2.5.RELEASE.jar
spring-context-3.2.5.RELEASE.jar
spring-core-3.2.5.RELEASE.jar
spring-expression-3.2.5.RELEASE.jar
spring-jdbc-3.2.5.RELEASE.jar
spring-tx-3.2.5.RELEASE.jar

连接mysql的配置文件
# druid.properties文件的配置
driverClassName=com.mysql.jdbc.Driver
url=jdbc:mysql://127.0.0.1:3306/db1
username=
password=
# 初始化连接数量
initialSize=5
# 最大连接数
maxActive=10
# 最大超时时间
maxWait=3000 连接数据库的工具
import com.alibaba.druid.pool.DruidDataSourceFactory;

import javax.sql.DataSource;
import java.io.IOException;
import java.io.InputStream;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.Properties; public class JDBCUtil {
//定义数据源
private static DataSource ds;
static{ try {
//定义Properties对象
Properties pro=new Properties();
//获取druid的地址,使用字节码获得
InputStream is = JDBCUtil.class.getClassLoader().getResourceAsStream("druid.properties");
pro.load(is);
ds = DruidDataSourceFactory.createDataSource(pro);
} catch (IOException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
} }
public static DataSource getDataSource(){
return ds;
}
public static Connection getConnection() throws SQLException {
return ds.getConnection();
}
} 操作数据库增删改查的方法
public class UserDaoImp implements UserDao{
//声明JDBCTemplate
private JdbcTemplate template=new JdbcTemplate(JDBCUtil.getDataSource());
//判断用户登录时的用户名和密码等
@Override
public User userLogin(User user) {
User user1 = null;
try {
String sql = "select * from user where username=? and password=?";
user1 = template.queryForObject(sql,
new BeanPropertyRowMapper<User>(User.class),
user.getUsername(),
user.getPassword());
} catch (Exception e) {
e.printStackTrace();
return null;
}
return user1;
}
//查询表中所有数据
@Override
public List<User> users() {
String sql="select * from user";
List<User> maps = template.query(sql, new BeanPropertyRowMapper<User>(User.class));
return maps;
}
//删除数据
@Override
public void delUser(int id) {
String sql="delete from user where id=?";
template.update(sql,id);
}
//添加数据
public void addUser(User user) {
String sql="insert into user(username,password,name,deptid,orgid,createdate) values('nc123456','nc123456',?,?,?,?)";
template.update(sql,user.getName(),user.getDeptid(),user.getOrgid(),new Date());
}
//修改数据
@Override
public void updateUser(User user) {
String sql="update user set deptid=?,orgid=? where id=?";
template.update(sql,user.getDeptid(),user.getOrgid(),user.getId());
}
}

JSP
<table class="table table-hover table-condensed table-bordered" align="center">

    <tr style="background-color: #b2dba1;text: center" >
<th><label class="checkbox-inline">
<input type="checkbox" name="uid" id="firstcb">
</label></th>
<th>序号</th>
<th>姓名</th>
<th>组织序号</th>
<th>部门序号</th>
<th>日期</th>
<th>操作</th>
</tr>
<c:forEach items="${users}" varStatus="list" var="lis">
<tr>
<td><label class="checkbox-inline">
<input type="checkbox" name="uid" value="${lis.id}">
</label></td>
<td>${list.count}</td>
<td>${lis.name}</td>
<td>${lis.orgid}</td>
<td>${lis.deptid}</td>
<td>${lis.createdate}</td>
<td><a class="btn btn-default" href="javascript:update(${lis.id});" role="button">修改</a>
<a class="btn btn-default" href="javascript:delecte(${lis.id});" role="button">删除</a></td>
</tr>
</c:forEach>
</table>
 
 

druid链接数据库的更多相关文章

  1. java 代码实现使用Druid 链接池获取数据库链接

    因为原先使用的c3p0链接池,时常出现:APPARENT DEADLOCK!!! Creating emergency threads for unassigned pending tasks,以及出 ...

  2. Druid链接池配置加密密码链接数据库

    Druid是阿里巴巴开源平台上一个数据库连接池实现,它结合了C3P0.DBCP.PROXOOL等DB池的优点,同时加入了日志监控,可以很好的监控DB池连接和SQL的执行情况,可以说是针对监控而生的DB ...

  3. 4、原生jdbc链接数据库常用资源名

    原生jdbc链接数据库要素:#MySql:String url="jdbc:mysql://localhost:3306/数据库名";String name="root& ...

  4. 诡异的druid链接池链接断开故障经验总结

    背景 症状 排查 修复 背景 最近在陆续做机房升级相关工作,配合DBA对产线数据库链接方式做个调整,将原来直接链接读库的地址切换到统一的读负载均衡的代理 haproxy 上,方便机柜和服务器的搬迁. ...

  5. PHP学习-链接数据库

    链接数据库文件:conn.php <?php $conn = mysql_connect("localhost:3306","root","us ...

  6. PHP 链接数据库1(连接数据库&简单的登录注册)

    对 解析变量的理解 数据库的名称和表的名称不能重复 从结果中取出的数据   都是以数组的形式取出的 1.PHP查询数据库中的某条信息 //PHP链接数据库 /*1.造链接对象 IP地址 用户名 密码 ...

  7. JDBC的使用(一):引用外部jar;代码链接数据库

    一:引用外部jar 1.首先不jar文件放到项目下: 2.在Eclipse中,右键相应的项目--构建路径--配置构建路径--库--添加外部jar:选中-打开-应用-确定. 二:代码链接数据库 1.加载 ...

  8. Connect to Database Using Custom params链接数据库配置参数说明

    使用RF的关键字Connect to Database Using Custom params链接数据库,对应的参数说明: a)     第一个参数我使用的是cx_Oracle,就写这个 b)     ...

  9. php链接数据库

      1:找到 ySQL服务器 $conn = mysql_connect("localhost","","") or die("链 ...

随机推荐

  1. JQuery之选择器的类型

    JQuery中的选择器数量和JavaScript中的选择器数量相差无几,JQuery中的选择器类型如下图: 代码实现: <script src="JS/jquery-3.4.1.js& ...

  2. Python协程与Go协程的区别二

    写在前面 世界是复杂的,每一种思想都是为了解决某些现实问题而简化成的模型,想解决就得先面对,面对就需要选择角度,角度决定了模型的质量, 喜欢此UP主汤质看本质的哲学科普,其中简洁又不失细节的介绍了人类 ...

  3. 转:FileSync plugin for Eclipse 安装注意事项 Eclipse文件同步插件

    习惯了使用MyEclipse,各种插件不用自己安装,觉得开发起来很方便,现在大家都用Eclipse了,还有不用Eclipse用更高级的,IT当然开发大型项目没人用UltraEdit吧,虽然是一个不错的 ...

  4. luogu P2272 [ZJOI2007]最大半连通子图

    题目描述 一个有向图G=(V,E)称为半连通的(Semi-Connected),如果满足:?u,v∈V,满足u→v或v→u,即对于图中任意两点u,v,存在一条u到v的有向路径或者从v到u的有向路径.若 ...

  5. Tomcat下载安装并部署到IDEA(附带idea两种热部署设置方法)

    目录 Tomcat下载教程 Tomcat安装教程 Tomcat热部署到IDEA idea两种热部署设置方法 使用Idea的时候,修改了代码,需要反复的重启Tomcat,查看效果,是不是贼烦?还记得刚上 ...

  6. Unity3D for iOS初级教程:Part 3/3(上)

    转自:http://www.cnblogs.com/alongu3d/archive/2013/06/01/3111738.html 欢迎来到第三部分,这是Unity 3D for iOS初级系列教程 ...

  7. webpack4.0(三)--动态生成html

    webpack4.0--动态生成html 前言: webpack-dev-server实现了自动编译刷新浏览器,让编译出来的bundle.js托关于服务器根路径(电脑内存)中去.使用--content ...

  8. HDU1517 Multiply Game

    Stan and Ollie play the game of multiplication by multiplying an integer p by one of the numbers 2 t ...

  9. HDU 1808 Halloween treats

    Every year there is the same problem at Halloween: Each neighbour is only willing to give a certain ...

  10. SpringBoot系列之Spring Data Jpa集成教程

    SpringBoot系列之Spring Data Jpa集成教程 Spring Data Jpa是属于Spring Data的一个子项目,Spring data项目是一款集成了很多数据操作的项目,其下 ...