io.github.wujun728.sql.SqlEngine Maven / Gradle / Ivy
The newest version!
package io.github.wujun728.sql;
//import com.alibaba.fastjson2.JSONObject;
import cn.hutool.json.JSONObject;
import io.github.wujun728.sql.engine.DynamicSqlEngine;
import lombok.extern.slf4j.Slf4j;
import java.sql.*;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
@Slf4j
public class SqlEngine {
static DynamicSqlEngine engine = new DynamicSqlEngine();
public static DynamicSqlEngine getEngine() {
return engine;
}
/**
* 1、查询返回List
* 2、新增、修改、删除返回int,成功条数。
* 3、连接没有关闭,需要在调用方关闭
* @param connection
* @param sql
* @param jdbcParamValues
* @return
*/
public static Object executeSql(Connection connection, String sql, Map sqlParam,Boolean closeConn) throws SQLException {
Object obj = executeSql(connection,sql,sqlParam);
if(closeConn){
connection.close();
}
return obj;
}
public static Object executeSql(Connection connection, String sql, Map sqlParam) throws SQLException {
SqlMeta sqlMeta = SqlEngine.getEngine().parse(sql, sqlParam);
return SqlEngine.executeSql(connection, sqlMeta.getSql(), sqlMeta.getJdbcParamValues());
}
public static Object executeSql(Connection connection, String sql, List