📄 tools.java
字号:
package org.digitstore.util;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Vector;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
/**
* 类功能 :公共工具类 <br>
*/
public class Tools {
private static Log logger = LogFactory.getLog(Tools.class);
public static String encodeGB(String parameter) {
try {
if (parameter == null) {
return parameter;
} else {
return new String(parameter.getBytes("ISO-8859-1"), "GBK");
}
} catch (Exception e) {
return parameter;
}
}
public static String encodeISO(String parameter) {
try {
if (parameter == null) {
return parameter;
} else {
return new String(parameter.getBytes("GBK"), "ISO-8859-1");
}
} catch (Exception e) {
return parameter;
}
}
public static Vector str2Vector(String[] str) {
Vector ret = new Vector();
if (str == null) {
return ret;
}
for (int i = 0; i < str.length; i++) {
ret.add(str[i]);
}
return ret;
}
public static String[] vector2String(Vector v) {
String[] r = new String[v.size()];
for (int i = 0; i < v.size(); i++) {
r[i] = (String) v.get(i);
}
return r;
}
public static boolean isDouble(Object teststr) {
if (teststr == null) {
return false;
}
try {
Double.parseDouble(teststr.toString());
return true;
} catch (Exception e) {
return false;
}
}
public static boolean isInt(Object teststr) {
if (teststr == null) {
return false;
}
try {
Long.parseLong(teststr.toString());
return true;
} catch (Exception e) {
return false;
}
}
public static String trimStr(String str) {
if (str == null) {
return "";
}
return str.trim();
}
/**
* 年月日数组合并为整个的数组
*/
public static String[] join(String[] year, String[] month, String[] day,
char c) {
for (int i = 0; i < year.length; i++) {
year[i] += (c + month[i] + c + day[i]);
}
return year;
}
private static DateFormat formater = null;
static {
formater = new SimpleDateFormat("yy-MM-dd HH:mm:ss");
}
/**
* 将Date类型转换成数据库日期类型格式的字符串
*
* @param date
* @return
*/
public static String transDate2SQLString(Date date) {
return formater.format(date);
}
/**
* 将数据库日期类型格式的字符串转换成Date类型
*
* @param date
* @return
*/
public static Date transSQLString2Date(String str) {
try {
return formater.parse(str);
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
/**
* 从ApplicationData表中获取某个表的将要插入的id值
*
* @return
*/
synchronized public static int getNextID(String tableName) {
int result = -1;
DBCon con = new DBCon("study");
String sql = "SELECT * FROM ApplicationData WHERE dataName='"
+ tableName + "'";
String sqlUpdate = null;
DBSet rs = null;
try {
rs = con.executeQuery(sql);
result = Integer.parseInt(rs.get(0, "numberValue"));
sqlUpdate = "UPDATE ApplicationData SET numberValue="
+ (result + 1) + " WHERE dataName='" + tableName + "'";
con.executeUpdate(sqlUpdate);
con.commit();
} catch (Exception e) {
con.rollback();
result = -1;
logger.debug("getNextID Error!" + e);
} finally {
con.close();
}
return result;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -