You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
58 lines
2.1 KiB
58 lines
2.1 KiB
package com.fr.plugin.decision.http; |
|
|
|
import com.fr.decision.fun.impl.BaseHttpHandler; |
|
import com.fr.json.JSONObject; |
|
import com.fr.log.FineLoggerFactory; |
|
import com.fr.plugin.decision.utils.JdbcUtils; |
|
import com.fr.third.springframework.web.bind.annotation.RequestMethod; |
|
import com.fr.web.utils.WebUtils; |
|
|
|
import javax.servlet.http.HttpServletRequest; |
|
import javax.servlet.http.HttpServletResponse; |
|
import java.net.URLDecoder; |
|
import java.sql.Connection; |
|
import java.sql.Statement; |
|
|
|
public class IfTableExistHttpHandler extends BaseHttpHandler { |
|
@Override |
|
public RequestMethod getMethod() { |
|
return null; |
|
} |
|
|
|
@Override |
|
public String getPath() { |
|
return "/excelmng/iftableexist"; |
|
} |
|
|
|
@Override |
|
public boolean isPublic() { |
|
return false; |
|
} |
|
|
|
@Override |
|
public void handle(HttpServletRequest req, HttpServletResponse res) throws Exception { |
|
String connection = WebUtils.getHTTPRequestParameter(req, "connection"); |
|
String tableName = URLDecoder.decode(WebUtils.getHTTPRequestParameter(req, "tableName")); |
|
|
|
Connection conn = JdbcUtils.getConnection(connection); |
|
Statement smt = null; |
|
|
|
try { |
|
if (conn == null){ |
|
FineLoggerFactory.getLogger().error("HW_excel导入:" + connection + "数据连接创建失败"); |
|
WebUtils.printAsJSON(res,new JSONObject().put("status","fail").put("errorText",connection + "数据连接创建失败,请检查该数据连接是否正常!")); |
|
return; |
|
} |
|
smt = conn.createStatement(); |
|
smt.executeQuery("select count(1) from " + tableName); |
|
|
|
// 能正常执行说明表已存在,返回fail |
|
FineLoggerFactory.getLogger().error("HW_excel导入:" + tableName + "已存在"); |
|
WebUtils.printAsJSON(res,new JSONObject().put("status","fail").put("errorText","表" + tableName + "已存在,请重新输入表名!")); |
|
} catch (Exception e) { |
|
WebUtils.printAsJSON(res,new JSONObject().put("status","success")); |
|
} finally { |
|
JdbcUtils.closeConn(conn,null, smt); |
|
} |
|
} |
|
}
|
|
|