Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
327784354c | ||
|
|
1bec66a97c | ||
|
|
273332c720 | ||
|
|
5b2586112a |
@@ -16,8 +16,9 @@ import java.util.Map;
|
|||||||
public class DBUtil {
|
public class DBUtil {
|
||||||
|
|
||||||
// 四大金刚
|
// 四大金刚
|
||||||
|
String dname = ReadTxt.getSetting(null, "setting.ini", "MySqlName","test");
|
||||||
String driver = "com.mysql.jdbc.Driver";// 驱动名称
|
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 username = ReadTxt.getSetting(null, "setting.ini", "MySqlUserName","root");// 用户名
|
||||||
String password = ReadTxt.getSetting(null, "setting.ini", "MySqlPassWord","cheng355217");// 密码
|
String password = ReadTxt.getSetting(null, "setting.ini", "MySqlPassWord","cheng355217");// 密码
|
||||||
|
|
||||||
@@ -25,6 +26,15 @@ public class DBUtil {
|
|||||||
Connection con = null;// 连接对象
|
Connection con = null;// 连接对象
|
||||||
PreparedStatement pstmt = null;// 语句对象
|
PreparedStatement pstmt = null;// 语句对象
|
||||||
ResultSet rs = 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 {
|
try {
|
||||||
Class.forName(driver);
|
Class.forName(driver);
|
||||||
con = DriverManager.getConnection(url, username, password);
|
con = DriverManager.getConnection(url, username, password);
|
||||||
|
con.prepareStatement("set names utf8mb4");
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
// TODO Auto-generated catch block
|
// TODO Auto-generated catch block
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
@@ -74,6 +85,7 @@ public class DBUtil {
|
|||||||
* @return 影响行数
|
* @return 影响行数
|
||||||
*/
|
*/
|
||||||
public int execUpdate(String sql, Object[] params) {
|
public int execUpdate(String sql, Object[] params) {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
this.getConnection();// 获得连接对象
|
this.getConnection();// 获得连接对象
|
||||||
this.pstmt = this.con.prepareStatement(sql);// 获得预设语句对象
|
this.pstmt = this.con.prepareStatement(sql);// 获得预设语句对象
|
||||||
@@ -193,31 +205,6 @@ public class DBUtil {
|
|||||||
return null;
|
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
|
* @param obj
|
||||||
|
|||||||
Reference in New Issue
Block a user