jdbc环境配置。
driver=com.mysql.jdbc.Driver
url=jdbc:mysql://localhost:3306/user
username=root
password=123456
日期格式工具方法。
package com.wh.utils;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
public class DateUtil {
public static Date dateParse(String regdate, String pattern) {
SimpleDateFormat sdf = new SimpleDateFormat(pattern);
try {
return sdf.parse(regdate);
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return new Date();
}
}
jdbc数据库连接池获得工具方法。
package com.wh.utils;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ResourceBundle;
public class DBUtil {
private static ResourceBundle resourceBundle=ResourceBundle.getBundle("resource/DBConfig");
public static Connection getConnection() {
Connection connection = null;
try {
Class.forName(resourceBundle.getString("driver"));
try {
connection = DriverManager.getConnection(resourceBundle.getString("url"), resourceBundle.getString("username"), resourceBundle.getString("password"));
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return connection;
}
/*public static void main(String[] args) {
System.out.println(getConnection());
}
main 方法可以让Java类测试运行
*/
public static void closeConnection(Connection connection,PreparedStatement preparedStatement,ResultSet resultSet) {
if(resultSet!=null) {
try {
resultSet.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}else if(preparedStatement!=null) {
try {
preparedStatement.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}else if(connection!=null) {
try {
connection.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
注册状态工具方法。
package com.wh.utils;
/*
* 注册状态的枚举类
*/
public enum RegisterStatus {
SUCCESS, FAILURE, REAISTERED
}