📄 cdirectexecsql.java
字号:
/*
SYS_201901
推送主页区查询
*/
package com.lgm.framework.system;
import java.util.*;
import java.sql.*;
import com.lgm.framework.util.*;
public class CDirectExecSql implements IBusiService{
public int execute(Connection conn,ValueObject recvPack,ValueObject sendPack) throws Exception{
if(conn==null || recvPack==null || sendPack==null) return 0;
String action_id = recvPack.getActionID() ; //动作类型
if(action_id==null) action_id = "execute";
return direct_exec_sql(conn,recvPack,sendPack);
}
public static int direct_exec_sql(Connection conn,ValueObject recvPack,ValueObject sendPack) throws Exception{
if(conn==null || recvPack==null || sendPack==null) return 0;
int iSuccFlag = 0 ;//成功标志
String strMsg = null;//成功信息
Statement st = null;
ResultSet rs = null;
ArrayList fList = null;
ArrayList aList = null;
HashMap aHash = null;
ResultSetMetaData rsdm = null;
String strSQL = "";
String action_id = recvPack.getActionID() ;
HashMap hashPara = recvPack.getDataMap("PARAMETER") ; //参数信息
HashMap hashUser = recvPack.getDataMap("LOGIN_USER"); //用户信息
String sql_expr = CommFunc.getValue(hashPara,"sql_expr" , "" ,true);
String f_name = null;
String f_value= null;
int iLoop = 0;
int iLoopNum = 0;
try{
if(sql_expr==null || sql_expr.equals("")){
return sendPack.setErrMsg(-1010001,"SQL语句为空");
}
if(action_id==null) action_id = "";
action_id = action_id.trim().toLowerCase();
try{
st = conn.createStatement();
if(action_id.equals("query")){
rs = st.executeQuery(sql_expr);
if(rs!=null) rsdm = rs.getMetaData();
iLoopNum = 0;
if(rsdm!=null) iLoopNum = rsdm.getColumnCount();
for (iLoop=1;iLoop<=iLoopNum;iLoop++){
f_name = rsdm.getColumnName(iLoop);
if(f_name==null || f_name.equals("")) continue;
f_name =f_name.trim().toLowerCase();
if(fList==null) {
fList = new ArrayList();
sendPack.setValue("f_list",fList);
}
fList.add(f_name);
}
iLoopNum = 0;
if(fList!=null) iLoopNum = fList.size();
while (rs != null && rs.next()) {
aHash =new HashMap();
for (iLoop=1;iLoop<=iLoopNum;iLoop++){
f_name = (String)fList.get(iLoop);
f_value= rs.getString(f_name);
aHash.put(f_name,f_value);
}
if(aList==null) {
aList = new ArrayList();
sendPack.setValue("data_list",aList);
}
aList.add(aHash);
}
iSuccFlag = 0;
if(aList!=null) iSuccFlag = aList.size();
strMsg = "执行成功! 数据["+iSuccFlag+"]条";
return sendPack.setErrMsg(iSuccFlag,strMsg);
}else{
iSuccFlag = st.executeUpdate(sql_expr);
strMsg = "执行成功! 影响数据["+iSuccFlag+"]条";
return sendPack.setErrMsg(iSuccFlag,strMsg);
}
}catch(SQLException se){
iSuccFlag = -1010002;
strMsg = "SQL异常:"+se.getMessage();
sendPack.setException(se);
return sendPack.setErrMsg(iSuccFlag,strMsg);
}catch(Exception e){
iSuccFlag = -1010002;
strMsg = "执行SQL异常"+e.getMessage();
sendPack.setException(e);
return sendPack.setErrMsg(iSuccFlag,strMsg);
}
}finally{
if(st!=null) try{st.close();}catch(Exception e){};
if(rs!=null) try{rs.close();}catch(Exception e){};
st = null;
rs = null;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -