淘宝女人街祝您购物愉快: 淘宝商城  淘宝女装  淘宝男装  美容护肤  数码频道  食品/特产
分类: Java专栏 |
预览模式: 普通 | 列表

jar连接数据库出现断开的解决方案

1. 采用JDBC连接数据库,如:DB2

 /**
  * 建立联接
  *
  * @return
  */
 public Connection getConnection() {
  try {
   conn = null;
   Class.forName(driverClassName).newInstance();
   log.debug("创建Mon连接……");
   conn = DriverManager.getConnection(app_url, app_user, app_password);
   log.debug("Mon连接创建成功!");
  } catch (Exception e) {
   log.debug("Mon连接创建失败!");
   log.error(e);
  }
  return conn;
 }

2. 实际应用

 

查看更多...

分类:Java专栏 | 固定链接 | 查看次数: 263

java读取资源文件信息

 private static final String CONFIG = "conf";
 private static ResourceBundle CONFIG_S = ResourceBundle.getBundle(CONFIG);

 private Conf() {
 }

 public static String getString(String key) {
  try {
   return CONFIG_S.getString(key);
  } catch (MissingResourceException e) {
   e.printStackTrace();
  }
  return "";
 }

分类:Java专栏 | 固定链接 | 查看次数: 250

java提前N天的日期

 /**
  * 提前N天的日期
  *
  * @param date
  * @param days
  * @return
  */
 public static Date beforeDate(Date date, int days) {
  java.util.Calendar c = java.util.Calendar.getInstance();
  c.setTime(date);
  c.add(java.util.Calendar.DAY_OF_YEAR, -days);
  return c.getTime();

 }

比如取当天的前一天日期时间:类文件.beforeDate(new Date(),1)

分类:Java专栏 | 固定链接 | 查看次数: 293

java需要格式化的日期对象

写一个方法,比如公共文件里:

 public static String formatDateToStr(Date date, String formatter) {
  if (date == null)
   return "";
  try {
   return new java.text.SimpleDateFormat(formatter).format(date);
  } catch (Exception e) {
   e.printStackTrace();
  }
  return "";
 }

取当天的日期:

 public static String today() {
  return formatDateToStr(new Date(),“YYYY-MM-DD”);
 }

分类:Java专栏 | 固定链接 | 查看次数: 262

Java计算指定年月的日期数

/**
  *
  * @param year
  * @param month
  * @return
  */
 public static int maxDayOfMonth(int year, int month) {
  switch (month) {
  case 1:
  case 3:
  case 5:
  case 7:
  case 8:
  case 10:
  case 12:
   return 31;
  case 4:
  case 6:
  case 9:
  case 11:
   return 30;
  case 2:
   boolean isRunYear = (year % 400 == 0)
     || (year % 4 == 0 && year % 100 != 0);
   return isRunYear ? 29 : 28;
  default:
   return 31;
  }
 }
分类:Java专栏 | 固定链接 | 查看次数: 274

获取Request中的参数,并且去除NULL

public static String get(HttpServletRequest request, String param,
   String defValue) {
  String value = request.getParameter(param);
  return null == value ? defValue : value.trim();
 }
分类:Java专栏 | 固定链接 | 查看次数: 251