Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
327784354c | ||
|
|
1bec66a97c | ||
|
|
273332c720 | ||
|
|
5b2586112a | ||
|
|
c843272f03 | ||
|
|
9f6314c9e9 |
@@ -16,8 +16,9 @@ import java.util.Map;
|
||||
public class DBUtil {
|
||||
|
||||
// 四大金刚
|
||||
String dname = ReadTxt.getSetting(null, "setting.ini", "MySqlName","test");
|
||||
String driver = "com.mysql.jdbc.Driver";// 驱动名称
|
||||
String url = "jdbc:mysql://"+ReadTxt.getSetting(null, "setting.ini", "MySqlIP","127.0.0.1")+":"+ReadTxt.getSetting(null, "setting.ini", "MySqlPort","3306")+"/"+ReadTxt.getSetting(null, "setting.ini", "MySqlName","test")+"?useUnicode=true&characterEncoding=UTF-8&useOldAliasMetadataBehavior=true&autoReconnect=true&useSSL=false";// 连接
|
||||
String url = "jdbc:mysql://"+ReadTxt.getSetting(null, "setting.ini", "MySqlIP","127.0.0.1")+":"+ReadTxt.getSetting(null, "setting.ini", "MySqlPort","3306")+"/"+dname+"?useOldAliasMetadataBehavior=true&autoReconnect=true&useSSL=false";// 连接
|
||||
String username = ReadTxt.getSetting(null, "setting.ini", "MySqlUserName","root");// 用户名
|
||||
String password = ReadTxt.getSetting(null, "setting.ini", "MySqlPassWord","cheng355217");// 密码
|
||||
|
||||
@@ -25,6 +26,15 @@ public class DBUtil {
|
||||
Connection con = null;// 连接对象
|
||||
PreparedStatement pstmt = null;// 语句对象
|
||||
ResultSet rs = null;// 结果集对象
|
||||
|
||||
|
||||
public DBUtil(String dbname){
|
||||
if(dbname!=null&&dbname.trim().length()>0)
|
||||
this.dname = dbname;
|
||||
}
|
||||
|
||||
public DBUtil(){
|
||||
}
|
||||
|
||||
/**
|
||||
* 获得连接对象
|
||||
@@ -37,6 +47,7 @@ public class DBUtil {
|
||||
try {
|
||||
Class.forName(driver);
|
||||
con = DriverManager.getConnection(url, username, password);
|
||||
con.prepareStatement("set names utf8mb4");
|
||||
} catch (Exception e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
@@ -74,6 +85,7 @@ public class DBUtil {
|
||||
* @return 影响行数
|
||||
*/
|
||||
public int execUpdate(String sql, Object[] params) {
|
||||
|
||||
try {
|
||||
this.getConnection();// 获得连接对象
|
||||
this.pstmt = this.con.prepareStatement(sql);// 获得预设语句对象
|
||||
@@ -193,31 +205,6 @@ public class DBUtil {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 搜索统计
|
||||
*
|
||||
* @param search
|
||||
* @return
|
||||
*/
|
||||
public boolean searchCount(String search) {
|
||||
String resid = "0";
|
||||
List<Map<String, Object>> res = execQuery(
|
||||
"select id from byx_count where searchstr =?",
|
||||
new String[] { search });
|
||||
if (res != null && res.size() > 0) {
|
||||
resid = res.get(0).get("id").toString();
|
||||
int i = execUpdate(
|
||||
"update byx_count set countsum = countsum+1 where id = "
|
||||
+ resid, null);
|
||||
return i > 0 ? true : false;
|
||||
} else {
|
||||
int i1 = execUpdate(
|
||||
"insert into byx_count(countsum,searchstr) values(1,?)",
|
||||
new String[] { search });
|
||||
return i1 > 0 ? true : false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取对象的属性,返回键值对
|
||||
* @param obj
|
||||
|
||||
@@ -617,6 +617,65 @@ public class ReadTxt {
|
||||
/**************/
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 删除全部内容
|
||||
*
|
||||
* @param path
|
||||
* 文件地址
|
||||
* @param nullString
|
||||
* 设置值为空时默认返回的内容
|
||||
* @return string
|
||||
*/
|
||||
public static void delAll(ServletContext servletContext, String path) {
|
||||
|
||||
|
||||
/**************/
|
||||
// 如果存在,则追加内容;如果文件不存在,则创建文件
|
||||
if(path.indexOf("./")==0)
|
||||
path =path.substring(1, path.length());
|
||||
|
||||
if (servletContext == null) {
|
||||
if(path.indexOf(":") <= 0&&path.indexOf("/") <0)
|
||||
path = "D:\\scbox_settings\\" + path;
|
||||
} else {
|
||||
path = servletContext.getRealPath(path);
|
||||
}
|
||||
|
||||
try {
|
||||
File file = new File(path);
|
||||
if (file.isFile() && file.exists()) { // 判断文件是否存在
|
||||
|
||||
// 把新内容覆盖写入文件
|
||||
PrintWriter out = new PrintWriter(new BufferedWriter(
|
||||
new OutputStreamWriter(new FileOutputStream(path),
|
||||
"UTF-8")));
|
||||
out.write("".toString());
|
||||
out.flush();
|
||||
out.close();
|
||||
|
||||
} else {// 不存在,创建
|
||||
String path2 = path.substring(0, path.replace("\\", "/").lastIndexOf("/"));
|
||||
File file1 = new File(path2);
|
||||
// 如果文件夹不存在则创建
|
||||
if (!file1.exists() && !file1.isDirectory()) {
|
||||
file1.mkdirs();
|
||||
}
|
||||
File file2 = new File(path);
|
||||
if (!file2.exists()) {
|
||||
file2.createNewFile();
|
||||
}
|
||||
|
||||
}
|
||||
} catch (IOException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
/**************/
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
|
||||
@@ -162,6 +162,79 @@ public class Utils {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 判断某个时间是否过期。传进来一个旧时间,和有效天数,判断今天这个旧时间是否过期
|
||||
*
|
||||
* @param d
|
||||
* 旧时间 "2019-8-5"
|
||||
* @param day
|
||||
* 有效天数
|
||||
* @return true:没有过期;false:过期了
|
||||
*/
|
||||
public static boolean dateout(String d, int day) {
|
||||
if (d == null || "".equals(d) || "null".equals(d))
|
||||
return false;
|
||||
Date date = Utils.dateadd(Utils.string2Date(d), day);
|
||||
Date newdate = new Date();
|
||||
int i = date.compareTo(newdate);
|
||||
if (i >= 0) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 计算两个时间相差的秒数
|
||||
*
|
||||
* @param endDate
|
||||
* 结束时间 null为当前
|
||||
* @param nowDate
|
||||
* 开始时间
|
||||
* @return
|
||||
*/
|
||||
public static long datePoor(Date endDate, Date nowDate) {
|
||||
|
||||
if(endDate==null) endDate = new Date();
|
||||
|
||||
long ns = 1000;// 一秒
|
||||
|
||||
// 获得两个时间的毫秒时间差异
|
||||
|
||||
long diff = endDate.getTime() - nowDate.getTime();
|
||||
|
||||
long sec = diff / ns;// 计算差多少秒
|
||||
return sec;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 计算两个时间相差的秒数
|
||||
*
|
||||
* @param endDate
|
||||
* 结束时间 null为当前
|
||||
* @param nowDate
|
||||
* 开始时间
|
||||
* @return
|
||||
*/
|
||||
public static long datePoor(String endDates, String nowDates) {
|
||||
if(endDates==null) endDates=Utils.date2String(null, null);
|
||||
Date endDate = Utils.string2Date(endDates, null);
|
||||
Date nowDate = Utils.string2Date(nowDates, null);
|
||||
|
||||
long ns = 1000;// 一秒
|
||||
|
||||
// 获得两个时间的毫秒时间差异
|
||||
|
||||
long diff = endDate.getTime() - nowDate.getTime();
|
||||
|
||||
long sec = diff / ns;// 计算差多少秒
|
||||
return sec;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 设置定时器启动时间
|
||||
* @param format 格式 yyyy-MM-dd 07:30:00
|
||||
@@ -237,28 +310,6 @@ public class Utils {
|
||||
return s2;
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断某个时间是否过期。传进来一个旧时间,和有效天数,判断今天这个旧时间是否过期
|
||||
*
|
||||
* @param d
|
||||
* 旧时间 "2019-8-5"
|
||||
* @param day
|
||||
* 有效天数
|
||||
* @return true:没有过期;false:过期了
|
||||
*/
|
||||
public static boolean dateout(String d, int day) {
|
||||
if (d == null || "".equals(d) || "null".equals(d))
|
||||
return false;
|
||||
Date date = Utils.dateadd(Utils.string2Date(d), day);
|
||||
Date newdate = new Date();
|
||||
int i = date.compareTo(newdate);
|
||||
if (i >= 0) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* URL解析与转义
|
||||
*
|
||||
@@ -690,28 +741,6 @@ public class Utils {
|
||||
return Long.valueOf(str2);
|
||||
}
|
||||
|
||||
/**
|
||||
* 计算两个时间相差的秒数
|
||||
*
|
||||
* @param endDate
|
||||
* 结束时间
|
||||
* @param nowDate
|
||||
* 开始时间
|
||||
* @return
|
||||
*/
|
||||
public static long getDatePoor(Date endDate, Date nowDate) {
|
||||
|
||||
long ns = 1000;// 一秒
|
||||
|
||||
// 获得两个时间的毫秒时间差异
|
||||
|
||||
long diff = endDate.getTime() - nowDate.getTime();
|
||||
|
||||
long sec = diff / ns;// 计算差多少秒
|
||||
return sec;
|
||||
|
||||
}
|
||||
|
||||
/**获取今天是周几,1-7*/
|
||||
public static long getWeekNum() {
|
||||
long[] weekDays = {7,1,2,3,4,5,6};
|
||||
|
||||
Reference in New Issue
Block a user