java web个人通讯录系统设计

现在开始上截图:

下面粘贴代码:

首先是目录结构:

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
 <head>
  <title>add.jsp</title>
  <script type="text/javascript" src="<c:url value='/jquery/contactor.js'/>"></script> 

   <style type="text/css">
  body{
    text-align: center;
    font-size:38px;
  }
     *{
      font-family:华文楷体;
      font-size:18px;
      color:#F0F";
  }
  h1{
    text-align: center;
    font-size:38px;
  }
  </style>

 </head>

 <body >

  <h1 style="font-size:38px;">添加新的联系人</h1>

  <form action="<c:url value='/ContactorServlet?userId=${userId } '/>" method="post" onsubmit="return checkForm()">
    <input type="hidden" name="method" value="4">
    <table border="1" width="50%" align="center">
      <tr>
        <td>姓名</td>
        <td>
          <input type="text" name="name" id="name" onfocus="nameFocus()" onblur="nameBlur()"/>
          <div id="nameId"></div>
        </td>
      </tr>
      <tr>
        <td>电话</td>
        <td>
          <input type="text" name="tel" id="tel" onfocus="telFocus()" onblur="telBlur()"/>
          <div id="telId"></div>
        </td>
      </tr>
      <tr>
        <td>地址</td>
        <td>
          <input type="text" name="address" id="address" />
        </td>
      </tr>
       <tr>
        <td>邮编</td>
        <td>
          <input type="text" name="zipcode" />
        </td>
      </tr>

    </table>
    <input style="margin-right:200px;" type="submit" value="添加"/>  

  </form>
 </body>
</html>
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
 <head>
  <title>edit.jsp</title>

  <script type="text/javascript" src="<c:url value='/jquery/contactor.js'/>"></script> 

   <style type="text/css">
  body{
    text-align: center;
    font-size:38px;
  }
     *{
      font-family:华文楷体;
      font-size:18px;
      color:#F0F";
  }
  h1{
    text-align: center;
    font-size:38px;
  }
  </style>

 </head>

 <body >
  <h1 style="font-size:38px;">修改联系人信息</h1>
  <form action="<c:url value='/ContactorServlet'/>" method="post" onsubmit="return checkForm()">
    <input type="hidden" name="method" value="6">
    <input type="hidden" name="id" value="${contactor.id }">
    <table border="1" width="50%" align="center">
      <tr>
        <td>姓名</td>
        <td>
          <input type="text" name="name" value="${contactor.name }" id="name" onfocus="nameFocus()" onblur="nameBlur()"/>
          <div id="nameId"></div>
        </td>
      </tr>
      <tr>
        <td>电话</td>
        <td>
          <input type="text" name="tel" value="${contactor.tel }" id="tel" onfocus="telFocus()" onblur="telBlur()" />
          <div id="telId"></div>
        </td>
      </tr>
      <tr>
        <td>地址</td>
        <td>
          <input type="text" id="address" name="address" value="${contactor.address }" />
        </td>
      </tr>
       <tr>
        <td>邮编</td>
        <td>
          <input type="text" name="zipcode" value="${contactor.zipcode }" />
        </td>
      </tr>  

    </table>
    <input style="margin-right:200px;" type="submit" value="更改"/>

  </form>
 </body>
</html>
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
 <head>
  <title>home.jsp</title>
 </head>

<frameset rows="100%,*">

  <frame name="body" src="<c:url value='/jsp/top.jsp'/>" />
</frameset>
</html>
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
 <head>
  <title>list.jsp</title>
   <style type="text/css">
  body{
    text-align: center;
    font-size:38px;
  }
     *{
      font-family:华文楷体;
      font-size:18px;
      color:#F0F";
  }
  h1{
    text-align: center;
    font-size:38px;
  }
  a:link{
    color: #999;
    text-decoration: none;
  }
  a:VISITED {
  text-decoration: none;
  color: #c60;
}
  a:HOVER {
  text-decoration: none;
  color: #00F;
}
  </style>

 </head>

 <body >
  <h1 style="font-size:38px;">欢迎登录到通信录系统</h1>
  <a style="font-size:26px;" href="<c:url value='/ContactorServlet?method=3&userId=${userId }'/>">查看联系人</a>
  <a style="font-size:26px;" href="<c:url value='/jsp/add.jsp'/>">添加联系人</a>
  <a   style="font-size:26px;" href="<c:url value='/jsp/top.jsp'/>">退出系统</a>

  <table border="1" align="center" width="60%">
    <tr>
      <th>姓名</th>
      <th>电话</th>
      <th>地址</th>
      <th>邮编</th>
      <th>操作1</th>
      <th>操作2</th>

    </tr>
    <c:forEach items="${contactorList }" var="c">
    <tr>
      <td>${c.name }</td>
      <td>${c.tel }</td>
      <td>${c.address }</td>
      <td>${c.zipcode }</td>

      <td><a href="<c:url value='/ContactorServlet?method=5&id=${c.id }'/>">编辑</a>
      </td>
      <td>
        <a href="<c:url value='/ContactorServlet?method=7&id=${c.id }'/>" >删除</a>
      </td>
    </tr>
    </c:forEach>
  </table>
 </body>
</html>
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
 <head>
  <title>top.jsp</title>
   <style type="text/css">
  body{
    text-align: center;
    font-size:38px;
  }
     *{
      font-family:华文楷体;
      font-size:18px;
      color:#F0F";
  }
  h1{
    text-align: center;
    font-size:38px;
  }
  </style>

 </head>

 <body >
  <h1 style="font-size:38px;">我的通信录</h1>

  <form action="<c:url value='/ContactorServlet'/>" method="post">
     <input type="hidden" name="method" value="1">
    用户名:<input type="text" name="username" /><br/>
    密    码:<input type="password" name="password" /><br/>
    <input type="submit" value="注册">
  </form>
 </body>
</html>
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
 <head>
  <title>top.jsp</title>
   <style type="text/css">
  body{
    text-align: center;
    font-size:38px;
  }
     *{
      font-family:华文楷体;
      font-size:18px;
      color:#F0F";
  }
  h1{
    text-align: center;
    font-size:38px;
  }
  </style>
 </head>

 <body >
  <h1 style="font-size:38px;">我的通信录</h1>

  <form action="<c:url value='/ContactorServlet'/>" method="post">
    <input type="hidden" name="method" value="2">
    用户名:<input type="text" name="username"/><br/>
    密   码:<input type="password" name="password"/><br/>
    <input type="submit" value="登录">
  <a href="<c:url value='/jsp/register.jsp'/>" target="body" >注册</a>
 </form>
 </body>
</html>

index.jsp

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<jsp:forward page="/jsp/home.jsp" />

contactor.js

//当鼠标放在客户名文本框时,给出一个提示文本
function nameFocus() {
  var nameId = document.getElementById("nameId");
  nameId.innerHTML = "请输入客户真实姓名";
}
//当鼠标离开客户名文本框时,给出一个文本提示
function nameBlur() {
  var name = document.getElementById("name");
  var nameId = document.getElementById("nameId");
  var reg= /^[\u4e00-\u9fa5]+$/;
  if(name.value == ""){
    nameId.innerHTML = "<font color='red'>联系人名不能为空</font>";
    return false;
  }
  if(reg.test(name.value) == false){
    nameId.innerHTML = "<font color='red'>联系人名只能输入中文简体汉字</font>";
    return false;
  }
  nameId.innerHTML = "<font color='green'>联系人名输入正确</font>";
  return true;

}
//当鼠标放在客户名文本框时,给出一个提示文本
function telFocus() {
  var telId = document.getElementById("telId");
  telId.innerHTML = "请输入手机号码";
}

//当鼠标离开客户名文本框时,给出一个文本提示
function telBlur() {
  var tel = document.getElementById("tel");
  var telId = document.getElementById("telId");
  var reg= /^(13|15|17|18)\d{9}$/;
  if(tel.value == ""){
    telId.innerHTML = "<font color='red'>手机号码不能为空</font>";
    return false;
  }
  if(reg.test(tel.value) == false){
    telId.innerHTML = "<font color='red'>手机号码输入不正确</font>";
    return false;
  }
  telId.innerHTML = "<font color='green'>手机号码输入正确</font>";
  return true;

}

//表单提交时验证输入内容的有效性
function checkForm() {
  var flagname = nameBlur();
  var flagtel = telBlur();
  if(flagname == true && flagtel == true ){
    return true;
  }else{
    alert("失败,请按提示输入信息 !")
    return false;
  }

}
package cn.edu.aynu.rjxy.bean;
/**
 * 联系人表属性
 * @author Administrator
 *
 */
public class Contactor {
  private int id;
  private int userId;
  private String name;
  private String tel;
  private String address;
  private String zipcode;

  public int getId() {
    return id;
  }
  public void setId(int id) {
    this.id = id;
  }
  public int getUserId() {
    return userId;
  }
  public void setUserId(int userId) {
    this.userId = userId;
  }
  public String getName() {
    return name;
  }
  public void setName(String name) {
    this.name = name;
  }
  public String getTel() {
    return tel;
  }
  public void setTel(String tel) {
    this.tel = tel;
  }
  public String getAddress() {
    return address;
  }
  public void setAddress(String address) {
    this.address = address;
  }
  public String getZipcode() {
    return zipcode;
  }
  public void setZipcode(String zipcode) {
    this.zipcode = zipcode;
  }

}
package cn.edu.aynu.rjxy.bean;
/**
 * 用户表属性
 * @author Administrator
 *
 */
public class User {
  private int id;
  private String username;
  private String password;
  public int getId() {
    return id;
  }
  public void setId(int id) {
    this.id = id;
  }
  public String getUsername() {
    return username;
  }
  public void setUsername(String username) {
    this.username = username;
  }
  public String getPassword() {
    return password;
  }
  public void setPassword(String password) {
    this.password = password;
  }

}
package cn.edu.aynu.rjxy.dao;

import java.sql.SQLException;
import java.util.List;

import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanHandler;
import org.apache.commons.dbutils.handlers.BeanListHandler;

import cn.edu.aynu.rjxy.bean.Contactor;
import cn.edu.aynu.rjxy.utils.JDBCUtils;

/**
 * 对linkman表的增删改查
 * @author Administrator
 *
 */
public class ContactorDao {
  private QueryRunner qr = new QueryRunner(JDBCUtils.getDataSource());
  /**
   * 添加联系人
   * @param c
   * @throws SQLException
   */
  public void insert(Contactor c,int userId) throws SQLException{
    String sql = "insert into linkman(name,tel,address,zipcode,userId) values(?,?,?,?,?)";
    qr.update(sql, c.getName(),c.getTel(),c.getAddress(),c.getZipcode(),userId);
  }
  /**
   * 删除联系人
   * @param cid
   * @throws SQLException
   */
  public void delete(int id) throws SQLException{
    String sql = "delete from linkman where id=?";
    qr.update(sql, id);
  }
  /**
   * 修改联系人
   * @param c
   * @throws SQLException
   */
  public void update(Contactor c,int userId) throws SQLException{
    String sql = "update linkman set name=?,tel=?,address=?,zipcode=?,userId=? where id=?";
    qr.update(sql, c.getName(),c.getTel(),c.getAddress(),c.getZipcode(),userId,c.getId());
  }
  /**
   * 根据userId查询联系人
   * @throws SQLException
   *
   */
  public List<Contactor> findAll(int userId) throws SQLException{
    String sql = "select * from linkman where userId = ?";
    List<Contactor> list = qr.query(sql, new BeanListHandler<Contactor>(Contactor.class),userId);
    return list;

  }
  /**
   * 根据id查询某个联系人
   * @throws SQLException
   *
   */
  public Contactor findByCid(int id) throws SQLException{
    String sql = "select * from linkman where id=?";
    Contactor c = qr.query(sql, new BeanHandler<Contactor>(Contactor.class), id);
    return c;
  }

}
package cn.edu.aynu.rjxy.dao;

import java.sql.SQLException;

import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanHandler;

import cn.edu.aynu.rjxy.bean.User;
import cn.edu.aynu.rjxy.utils.JDBCUtils;

/**
 * 对user表的查询
 * @author Administrator
 *
 */
public class UserDao {
  private QueryRunner qr = new QueryRunner(JDBCUtils.getDataSource());
  /**
   * 根据用户名和用户密码查询
   * @param cid
   * @return
   * @throws SQLException
   */
  public User findByCid(String username,String password) throws SQLException{
    String sql = "select * from user where username=?&&password=?";
    User u = qr.query(sql, new BeanHandler<User>(User.class), username,password);
    return u;
  }
  /**
   * 注册
   * @param c
   * @throws SQLException
   */
  public void register(User u) throws SQLException{
    String sql = "insert into user(username,password) values(?,?)";
    qr.update(sql, u.getUsername(),u.getPassword());
  }
}
package cn.edu.aynu.rjxy.service;

import java.sql.SQLException;
import java.util.List;

import cn.edu.aynu.rjxy.bean.Contactor;
import cn.edu.aynu.rjxy.dao.ContactorDao;

/**
 * 联系人功能处理
 * @author Administrator
 *
 */
public class ContactorService {
  //创建ContactorDao对象
  ContactorDao dao = new ContactorDao();
  /**
   * 添加联系人
   * @param c
   */
  public void add(Contactor c,int userId){
    try {
      dao.insert(c,userId);
    } catch (SQLException e) {
      throw new RuntimeException(e);
    }
  }
  /**
   * 删除联系人
   * @param cid
   */
  public void delete(int id){
    try {
      dao.delete(id);
    } catch (SQLException e) {
      throw new RuntimeException(e);
    }
  }
  /**
   * 加载(查询)联系人
   * @param cid
   */
  public List<Contactor> load(int userId){
    try {
      return dao.findAll(userId);
    } catch (SQLException e) {
      throw new RuntimeException(e);
    }
  }
  /**
   * 加载(查询)联系人(为修改做准备)
   * @param cid
   */
  public Contactor loadById(int id){
    try {
      return dao.findByCid(id);
    } catch (SQLException e) {
      throw new RuntimeException(e);
    }
  }
  /**
   * 编辑(修改)联系人信息
   * @param c
   */
  public void edit(Contactor c,int userId){
    try {
      dao.update(c,userId);
    } catch (SQLException e) {
      throw new RuntimeException(e);
    }
  }

}
package cn.edu.aynu.rjxy.service;

import java.sql.SQLException;

import cn.edu.aynu.rjxy.bean.User;
import cn.edu.aynu.rjxy.dao.UserDao;

/**
 *
 * @author Administrator
 *
 */
public class UserService {
  //创建ContactorDao对象
  UserDao dao = new UserDao();
  /**
   * 根据用户名和密码查询用户
   * @param cid
   */
  public User login(String username,String password){
    try {
      return dao.findByCid(username,password);
    } catch (SQLException e) {
      throw new RuntimeException(e);
    }
  }
  /**
   * 注册
   * @param c
   */
  public void register(User u){
    try {
      dao.register(u);
    } catch (SQLException e) {
      throw new RuntimeException(e);
    }
  }
}
package cn.edu.aynu.rjxy.servlet;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import cn.edu.aynu.rjxy.bean.Contactor;
import cn.edu.aynu.rjxy.bean.User;
import cn.edu.aynu.rjxy.service.ContactorService;
import cn.edu.aynu.rjxy.service.UserService;
import cn.edu.aynu.rjxy.utils.CommonsUtils;
/**
 * 处理联系人请求
 * @author Administrator
 *
 */
public class ContactorServlet extends HttpServlet {
  private ContactorService cs = new ContactorService();
  private UserService us = new UserService();
  private int userId;
  public void doGet(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {

    this.doPost(request, response);
  }

  /**
   * 通过获取表单中的隐藏字段method或者超链接中的method参数的值来区分调用执行那个方法来处理这个请求
   */
  public void doPost(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {
    //处理中文乱码
    request.setCharacterEncoding("UTF-8");
    response.setContentType("text/html;charset=UTF-8");
    //获取隐藏字段method的值,并把它转换为int型
    int method = Integer.parseInt(request.getParameter("method"));

    switch(method){
      case 1: this.register(request, response);
          break;
      case 2: this.login(request, response);
          break;
      case 3: this.query(request, response);
          break;
      case 4: this.add(request, response);
          break;
      case 5: this.loadForUpdate(request, response);
          break;
      case 6: this.edit(request, response);
          break;
      case 7:  this.delete(request, response);
          break;
    }

  }
  /**
   * 处理注册的请求
   * @param request
   * @param response
   * @throws ServletException
   * @throws IOException
   */
  public void register(HttpServletRequest request, HttpServletResponse response)
  throws ServletException, IOException {
    //使用CommonUtils工具类将请求数据封装到bean中
    User u = CommonsUtils.toBean(request.getParameterMap(), User.class);
    //执行添加客户业务
    us.register(u);
    //输出添加成功提示
    response.getWriter().print("注册成功,三秒钟自动跳转到登录界面");
    response.setHeader("Refresh","3;url=http://127.0.0.1:8099/addresslist/jsp/top.jsp"); 

  }
  /**
   * 处理登录的请求 method=2
   * @param request
   * @param response
   * @throws ServletException
   * @throws IOException
   */
  public void login(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {
    //从请求中解析用户名和密码
    String username = request.getParameter("username");
    String password = request.getParameter("password");
    //执行加载业务
    User u = us.login(username, password);
    if (u != null) {
      HttpSession session = request.getSession();
      session.setAttribute("userId", u.getId());
      response.getWriter().print("登录成功"+u.getId());
      //通过请求转发将pb带到list.jsp上去
      request.getRequestDispatcher("/jsp/list.jsp").forward(request, response);
    }else{
      response.getWriter().print("登录失败,即将跳转到登录页面,请重新登录......");
      response.setHeader("Refresh","3;url=http://127.0.0.1:8099/addresslist/jsp/top.jsp"); 

    }

  }
  /**
   * 处理查看联系人的请求 method=3
   * @param request
   * @param response
   * @throws ServletException
   * @throws IOException
   */
  public void query(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {
    HttpSession session = request.getSession();
     userId = (Integer) session.getAttribute("userId");
    //执行查询业务
    List<Contactor> list = cs.load(userId);
    //将list存放到request域中
    request.setAttribute("contactorList", list);
    System.out.println(list.size());
    //通过请求转发将查询结果带到list.jsp页面上显示
    request.getRequestDispatcher("/jsp/list.jsp").forward(request, response);

  }
  /**
   * 处理添加客户的请求
   * @param request
   * @param response
   * @throws ServletException
   * @throws IOException
   */
  public void add(HttpServletRequest request, HttpServletResponse response)
  throws ServletException, IOException {
    HttpSession session = request.getSession();
    userId = (Integer) session.getAttribute("userId");
    //使用CommonUtils工具类将请求数据封装到bean中
    Contactor c = CommonsUtils.toBean(request.getParameterMap(), Contactor.class);
    //执行添加客户业务
    cs.add(c,userId);
    //输出添加成功提示
    response.getWriter().print("添加成功,三秒后跳转到功能界面......");
    response.setHeader("Refresh","3;url=http://127.0.0.1:8099/addresslist/jsp/list.jsp");
  }
  /**
   * 处理加载某一个客户的请求
   * @param request
   * @param response
   * @throws ServletException
   * @throws IOException
   */
  public void loadForUpdate(HttpServletRequest request, HttpServletResponse response)
  throws ServletException, IOException {
    //从请求中获取客户的cid
    String ids = request.getParameter("id");
    int id = Integer.valueOf(ids);
    //执行加载业务
    Contactor c = cs.loadById(id);
    //将Customer对象c保存在request域中
    request.setAttribute("contactor", c);
    //通过请求转发将customer对象显示在list.jsp页面上
    request.getRequestDispatcher("/jsp/edit.jsp").forward(request, response);

  }
  /**
   * 处理更改某一联系人的请求
   * @param request
   * @param response
   * @throws ServletException
   * @throws IOException
   */
  public void edit(HttpServletRequest request, HttpServletResponse response)
  throws ServletException, IOException {
    HttpSession session = request.getSession();
    userId = (Integer) session.getAttribute("userId");
    //使用CommonUtils工具类将请求数据封装到bean中
    Contactor c = CommonsUtils.toBean(request.getParameterMap(), Contactor.class);
    //执行更改业务
    cs.edit(c,userId);
    //给客户端发送更改成功提示
    response.getWriter().print("更改成功,三秒后跳转到功能界面......");
    response.setHeader("Refresh","3;url=http://127.0.0.1:8099/addresslist/jsp/list.jsp"); 

  }
  /**
   * 处理删除某一联系人的请求
   * @param request
   * @param response
   * @throws ServletException
   * @throws IOException
   */
  public void delete(HttpServletRequest request, HttpServletResponse response)
  throws ServletException, IOException {
    //从请求中获取cid
    String cid = request.getParameter("id");
    int id = Integer.valueOf(cid);
    //执行删除客户业务
    cs.delete(id);
    //给客户端发送删除成功提示
    response.getWriter().print("删除成功,三秒后跳转到功能界面......");
    response.setHeader("Refresh","3;url=http://127.0.0.1:8099/addresslist/jsp/list.jsp"); 

}

}
package cn.edu.aynu.rjxy.utils;

import java.util.Map;
import java.util.UUID;

import org.apache.commons.beanutils.BeanUtils;
import org.apache.commons.beanutils.ConvertUtils;

/**
 * 提供UUID,实现表单数据封装到bean中
 * @author Administrator
 *
 */
public class CommonsUtils {
  /**
   * 返回一个UUID
   * @return
   */
  public static String uuid(){
    return UUID.randomUUID().toString().replace("-", "").toUpperCase();

  }

  /**
   * 把表单数据封装到bean中
   */
  public static <T> T toBean(Map data, Class<T> clazz){
    try{
      T bean = clazz.newInstance();
      BeanUtils.populate(bean, data);
      return bean;
    }catch (Exception e) {
      throw new RuntimeException(e);
    }
  }

}
package cn.edu.aynu.rjxy.utils;

import java.sql.Connection;
import java.sql.SQLException;

import javax.sql.DataSource;

import com.mchange.v2.c3p0.ComboPooledDataSource;

/**
 * 创建数据库连接池
 * @author Administrator
 *
 */
public class JDBCUtils {
  //读取的是C3P0-config默认配置创建数据库连接池对象
  private static DataSource ds = new ComboPooledDataSource();
  //获取数据库连接池对象
  public static DataSource getDataSource(){
    return ds;
  }
  //从池中获取连接
  public static Connection getConnection() throws SQLException{
    return ds.getConnection();
  }
}
<?xml version="1.0" encoding="UTF-8"?>
<c3p0-config>
  <!-- 默认配置,当使用ComboPooledDataSource无参构造器时,使用的就是这个配置 -->
  <default-config>
    <!-- 基本配置 -->
    <property name="jdbcUrl">jdbc:mysql://localhost:3306/linkman?characterEncoding=UTF-8</property>
    <property name="driverClass">com.mysql.jdbc.Driver</property>
    <property name="user">root</property>
    <property name="password">123456</property>
    <!-- 每次增量,当需要创建Connection对象时,一次创建几个 -->
    <property name="acquireIncrement">3</property>
    <!-- 当创建池对象后,池中应该有几个Connection对象 -->
    <property name="initialPoolSize">10</property>
    <!-- 池中最少Connection个数,如果少于这个值,就会创建Connection -->
    <property name="minPoolSize">2</property>
    <!-- 池中最大连接个数 -->
    <property name="maxPoolSize">10</property>
  </default-config>
</c3p0-config>

该工程需要的jar包:

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持我们。

(0)

相关推荐

  • Android实现通讯录效果——获取手机号码和姓名

    首先给大家展示下运行效果图: 由于通讯录在手机里是以数据库贮存的 所以我们可以通过一个方法 context.getContentResolver().query(Phone.CONTENT_URI, null, null, null, null); 来获得通讯录 ,这个方法返回一个游标的数据类型,通过moveToNext()方法来获取所有的手机号码信息 当然读取手机通讯录需要权限 在adnroidManifest文件中声明即可 由于我也实现了打电话的功能 所以也要声明权限 <uses-permi

  • Ionic实现仿通讯录点击滑动及$ionicscrolldelegate使用分析

    引言 在诺亚财富项目中,使用到了通讯录,如果只是简单的查看,我个人觉得可能过于单调,于是就在查看的基础上,增加了点击滑动的效果.目的有两个:1.体验不错.2.通讯录的数据量较大,我们在点击一个模块的同时,使这个模块滑动至最上层,可视范围也会变大. 效果 点击一个模块,页面即开始向上滑动,直到这个模块至于页面最上层. 这是点击前的地方,我们点击运营中心: 点击后就会有一个滑动的动画使这个模块滑动到顶部: 实现 获取元素,动态生成id 我们在点击一个元素的同时,我们需要让程序知道我们点击了哪里,是具

  • AngularJS + Node.js + MongoDB开发的基于高德地图位置的通讯录

    一.闲扯 有一天班长说了,同学们希望我开发一个可以共享位置的通讯录,于是自己简单设计了下功能.包括用户角色.发表微博.共享位置等等.这次也是有点私心的,为了锻炼最近看的angularjs,于是果断选择Node.js + MongoDB + angular.js的方案.当然,开发Node.js的体会越来越深刻.记得,去年leader告诉我说尽量让node的每一个服务只支撑一个业务功能,这样才能更方便的维护.当时特别想把一个Node服务做的特别强大.现在看来leader的做法是对的,我更加倾向于把n

  • 一个简单的python程序实例(通讯录)

    核心代码: 复制代码 代码如下: #!/usr/bin/python#Filename:friendbook.pyimport cPickle as pimport sysimport timeimport os ab={'Xdex':'cneds@fnedf.com',        'Laexly':'fev@fe.com',        'Fukc':'fexok@ver.com',        'Stifu':'stif@qq.com'} def Dumpfile(list):   

  • 使用adb命令向Android模拟器中导入通讯录联系人的方法

    本文实例讲述了使用adb命令向Android模拟器中导入通讯录联系人的方法.分享给大家供大家参考.具体实现方法如下: 使用adb提供的命令, 可以非常方便地从PC中将通讯录导入android模拟器中. 首先要先准备好固定格式的contacts.vcf文件, 该文件即android中的通讯录存储文件. 格式如下: 复制代码 代码如下: BEGIN:VCARD  VERSION:3.0  N:15200000000;;;;  TEL;TYPE=cell:15200000000  END:VCARD 

  • 30分钟学会用PHP写带数据库的简单通讯录第1/3页

    引用上篇文章的开场白: 我接触PHP也不是很久,所以有什么不足的地方,欢迎各位指正,让大家见笑了. 这篇小教程的对象是PHP初学者,都是些最简单.最基本的东西,因此高手们可以略过哦. 为了让各位初学者提起兴趣.尽快入门,这里写的是将是最简单,最基本的PHP程序,相信你只要有一点点的PHP基础知识,10分钟之内就能把它学会.没有PHP基础知识也没有关系,只要耐心的看,学会它也不会超过一个小时的. 我写这篇文章的目的是,和大家一起共同学习.共同进步,然后将PHP初学者们对PHP的恐惧心理驱赶到十万八

  • java微信企业号开发之通讯录

    上篇文章中介绍了聊天功能,这里介绍通讯录是如何实现的.首先要加载公司的所有部门,树形结构,然后点击进入部门的人员列表,点击人员能查看详细信息. 一.界面 公司部门的树形结构: 部门成员列表: 个人详细信息: 二.代码实现 1.controller /** * 加载部门列表 */ @RequestMapping("/addressListDepartmentjsp.do") public void addressListDepartment(HttpServletRequest requ

  • Android通讯录开发之删除功能的实现方法

    无论是Android开发或者是其他移动平台的开发,ListView肯定是一个大咖,那么对ListView的操作肯定是不会少的,上一篇博客介绍了如何实现全选和反选的功能,本篇博客介绍删除功能,删除列表中的项无谓就是及时刷新列表,这又跟UI线程扯上关系了,还是那句话,数据的更新通知一定要在UI线程上做,不然会出现各种错误,比如出现adapter数据源改变,但没有及时收到通知的情况.在执行遍历删除的时候,最好不要每删一个就直接通知,下面是我的实现方法,将需要删除的contact保存到一个List然后通

  • Android获取手机通讯录、sim卡联系人及调用拨号界面方法

    android获取手机通讯录联系人信息 复制代码 代码如下: private void getPhoneContacts() {        ContentResolver resolver = this.getContentResolver();                // 获取手机联系人       Cursor phoneCursor = resolver.query(Phone.CONTENT_URI,                  new String[] { Phone

  • iOS开发中使app获取本机通讯录的实现代码实例

    一.在工程中添加AddressBook.framework和AddressBookUI.framework 二.获取通讯录 1.在infterface中定义数组并在init方法中初始化 复制代码 代码如下: NSMutableArray *addressBookTemp;   - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {     addressBookTemp = [NSMut

随机推荐