SQL在in中传入参数类型问题
在in中写入:
SELECT REGEXP_SUBSTR(?,'[^,]+', 1, LEVEL) FROM DUAL
CONNECT BY REGEXP_SUBSTR(?, '[^,]+', 1, LEVEL) IS NOT NULL
且替换?占位符
计算字符串
String str = "1+2";
ScriptEngineManager manager = new ScriptEngineManager();
ScriptEngine engine = manager.getEngineByName("js");
String value = engine.eval(str).toString;
统计进程数量
/*
* 统计进程数量,适应与windows和linux
* @Author syp
* @param进程名称
* 返回值为进程个数
*/
public static int GetprocessNums(String processName) {
Runtime runtime = Runtime.getRuntime();
List<String> tasklist = new ArrayList<String>();
java.lang.Process process=null;
int count=0; //统计进程数
try {
/*
* 自适应执行查询进程列表命令
*/
Properties prop= System.getProperties();
//获取操作系统名称
String os= prop.getProperty("os.name");
if (os != null && os.toLowerCase().indexOf("linux") > -1) {
//1.适应与linux
BufferedReader reader =null;
process = runtime.exec("ps -ef");
//显示所有进程
process = Runtime.getRuntime().exec("ps -ef");
reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
String line = null;
while((line = reader.readLine())!=null){
if(line.contains(processName)){
System.out.println("line===>"+line);
count++;
}
}
} else {
//2.适应与windows
process = runtime.exec("tasklist");
BufferedReader br = new BufferedReader(new InputStreamReader(process.getInputStream()));
String s = "";
while ((s = br.readLine()) != null) {
if ("".equals(s)) {
continue;
}
tasklist.add(s+" ");
}
// 获取每列最长的长度
String maxRow = tasklist.get(1) + "";
String[] maxCol = maxRow.split(" ");
// 定义映像名称数组
String[] taskName = new String[tasklist.size()];
// 定义 PID数组
String[] taskPid = new String[tasklist.size()];
// 会话名数组
String[] taskSessionName = new String[tasklist.size()];
// 会话#数组
String[] taskSession = new String[tasklist.size()];
// 内存使用 数组
String[] taskNec = new String[tasklist.size()];
for (int i = 0; i < tasklist.size(); i++) {
String data = tasklist.get(i) + "";
for (int j = 0; j < maxCol.length; j++) {
switch (j) {
case 0:
taskName[i]=data.substring(0, maxCol[j].length()+1);
data=data.substring(maxCol[j].length()+1);
break;
case 1:
taskPid[i]=data.substring(0, maxCol[j].length()+1);
data=data.substring(maxCol[j].length()+1);
break;
case 2:
taskSessionName[i]=data.substring(0, maxCol[j].length()+1);
data=data.substring(maxCol[j].length()+1);
break;
case 3:
taskSession[i]=data.substring(0, maxCol[j].length()+1);
data=data.substring(maxCol[j].length()+1);
break;
case 4:
taskNec[i]=data;
break;
}
}
}
for (int i = 0; i < taskNec.length; i++) {
//打印进程列表
//System.out.println(taskName[i]+" "+taskPid[i]+" "+taskSessionName[i]+" "+taskSession[i]+" "+taskNec[i]);
if(taskName[i].contains(processName)){
count++;//用于进程计数
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
return count;
}
获取项目根路径
/**
* 返回项目根路径
* @returns {string}
*/
var getRootPath = function () {
var curWwwPath = window.document.location.href;
var pathName = window.document.location.pathname;
var pos = curWwwPath.indexOf(pathName);
var localhostPaht = curWwwPath.substring(0, pos);
var projectName = pathName.substring(0, pathName.substr(1).indexOf('/') + 1);
return (localhostPaht);
};
var api = getRootPath() + '/ssjg/';
跳转链接下载文件
var herf = top.CONTEXTPATH + "/task/downloadChrome.do?token="+top.currkey;
window.location.href = herf;
@Override
public void downloadChrome(HttpServletResponse response, HttpServletRequest request, Result result) throws Exception{
OutputStream os = null;
ZipUtil zipUtil = null;
FileInputStream fis = null;
String uri = request.getContextPath();
try {
String filePath = request.getSession().getServletContext().getRealPath("/") + "/WEB-INF/chrome/";
//默认的文件名
String filename = "chrome.exe";
File file = new File(filePath + filename);
fis = new FileInputStream(file);
//清空一下response对象
response.reset();
//指明这是一个下载的respond
response.setContentType("application/x-download");
//双重解码、防止乱码
filename = URLEncoder.encode(filename,"UTF-8");
response.setCharacterEncoding("UTF-8");
//设置在下载框默认显示的文件名
response.setHeader("Content-Disposition","attachment;filename=" + filename);
// 指明response的返回对象是文件流
response.setContentType("application/octet-stream");
//获取输出流
os = response.getOutputStream();
byte[] buff = new byte[1024];
int length = 0;
while ((length = fis.read(buff)) != -1){
os.write(buff,0,length);
}
result.setResultSuccess();
} catch (Exception e) {
if(e instanceof FileNotFoundException) {
result.setErrorMSG("无法找到谷歌浏览器安装包,请联系客服人员。<a href='"+uri+"/pages/indexcontent.html'>返回</a>");
}
e.printStackTrace();
} finally {
if (zipUtil != null) {
zipUtil.close();
}
if(fis != null){
fis.close();
}
if (os != null) {
os.close();
}
}
}
List< Map> 转 List< Object>
List<VoucherNoList> vouNoList = JSON.parseArray(JSON.toJSONString(list), VoucherNoList.class);
处理oracle sql 语句in子句参数超过1000项
/**
* <b>function:</b> 处理oracle sql 语句in子句中(where id in (1, 2, ..., 1000, 1001)),
* 如果子句中超过1000项就会报错。
* 这主要是oracle考虑性能问题做的限制。
* 如果要解决次问题,可以用 where id (1, 2, ..., 1000) or id (1001, ...)
* 但是,这种方法效率比较低
*
* @param ids in语句中的集合对象
* @param count in语句中出现的条件个数
* @param field in语句对应的数据库查询字段
* @return 返回 field in (...) or field in (...) 字符串
* @author hoojo
* @createDate 2012-8-31 下午02:36:03
*/
public static String getOracleSQLIn(List<?> ids, int count, String field) {
count = Math.min(count, 1000);
int len = ids.size();
int size = len % count;
if (size == 0) {
size = len / count;
} else {
size = (len / count) + 1;
}
StringBuilder builder = new StringBuilder();
for (int i = 0; i < size; i++) {
int fromIndex = i * count;
int toIndex = Math.min(fromIndex + count, len);
//System.out.println(ids.subList(fromIndex, toIndex));
String productId = StringUtils.defaultIfEmpty(StringUtils.join(ids.subList(fromIndex, toIndex), "','"), "");
if (i != 0) {
builder.append(" or ");
}
builder.append(field).append(" in ('").append(productId).append("')");
}
return StringUtils.defaultIfEmpty(builder.toString(), field + " in ('')");
}