包刀;
導入Java . text . parse exception;
導入Java . text . simple date format;
導入Java . util . calendar;
導入Java . util . date;
導入Java . util . list;
導入org . hibernate . criteria;
導入org . hibernate . session;
導入org . hibernate . session factory;
導入org . hibernate . CFG . configuration;
導入org . hibernate . criterion . expression;
導入實體。沈芬珍;
公共類IdDao {
私有靜態配置配置=新配置()。configure();
private static session factory session factory = configuration . build session factory();
私有靜態會話session = null
公共信息查詢(字符串){
Info info = null
StringBuffer stringBuffer =新的string buffer;
if(s.length()==18){
string end = string buffer . substring(17);
//system . out . println(end);
如果(!end . matches(" \ \ d | | x "){
返回null
}
}
else if(s.length()==15){
stringBuffer.insert(6," 19 ");
string buffer . append(" 3 ");
}
int I = integer . parse int(string buffer . substring(0,6));
//system . out . println(I);
session = session factory . open session();
criteria criteria = session . create criteria(Shen fenzhen . class);
criteria . add(expression . eq(" num ",I));
列表& ltShenfenzhen & gtlist = criteria . list();
字符串地址= null
嘗試{
address = list.get(0)。get address();
}catch(異常e) {
返回null
}
I = integer . parse int(string buffer . substring(16,17));
String sex = null
if(i%2==0){
性別= "女性";
}否則{
性別= "男性";
}
//system . out . println(I);
string buffer = new string buffer(string buffer . substring(6,14));
//string buffer . insert(4,"-");
//string buffer . insert(7,"-");
//system . out . println(string buffer);
string ss = string buffer . tostring();
simple date format date format = new simple date format(" yyyyMMdd ");
String brithday =
int year = 0;
int month = 0;
int day = 0;
嘗試{
date date = date format . parse(ss);
//system . out . println(date);
calendar calendar = calendar . getinstance();
calendar.setTime(日期);
year = calendar.get(Calendar。年份);
month = calendar.get(日歷。月)+1;
day = calendar.get(日歷。月日);
Brithday = (String)(year+“年”+month+“月”+day+“日”);
} catch (ParseException e) {
// TODO自動生成的catch塊
e . printstacktrace();
}
info =新信息(地址、生日、性別);
calendar c = calendar . getinstance();
int nowYear = c.get(Calendar。年份);
int nowMonth = c.get(日歷。月);
int nowDay = c.get(Calendar。月日);
if(now year & lt;年份){
info = null
} else if(now year = = year & amp;& ampnowMonth & lt月){
info = null
} else if(now year = = year & amp;& ampnowMonth = = month & amp& amp現在& lt日){
info = null
}
closeSession(會話);
返回信息;
}
//public static void main(String[]args){
//id Dao Dao = new id Dao();
//Dao . query(" 342522998711224513 ");
//system . out . println(" x "。匹配(" \ \ d | | x ");
// }
私有void closeSession(會話session){
如果(會話!=null){
session . close();
}
}
}