类 DataConnection

java.lang.Object
com.gdxsoft.easyweb.datasource.DataConnection

public class DataConnection extends Object
  • 构造器详细资料

    • DataConnection

      public DataConnection()
    • DataConnection

      public DataConnection(RequestValue rv)
    • DataConnection

      public DataConnection(String configName, RequestValue rv)
  • 方法详细资料

    • getTimeDiffMinutes

      public int getTimeDiffMinutes()
      用户和系统的时差(分钟)
      返回:
    • setTimeDiffMinutes

      public void setTimeDiffMinutes(int timeDiffMinutes)
      用户和系统的时差(分钟)
      参数:
      timeDiffMinutes - 分钟
    • updateAndClose

      public static String updateAndClose(String sql, String configName, RequestValue rv)
      执行更新并关闭连接
      参数:
      sql -
      configName -
      rv -
      返回:
      返回是否错误
    • updateAndClose

      public static String updateAndClose(StringBuilder sb, String configName, RequestValue rv)
    • updateBatchAndClose

      public static String updateBatchAndClose(String sqls, String configName, RequestValue rv)
      批量执行更新并关闭连接
      参数:
      sqls - 用;分割的sql字符串
      configName -
      rv -
      返回:
      返回是否错误
    • updateBatchAndClose

      public static String updateBatchAndClose(StringBuilder sb, String configName, RequestValue rv)
      批量执行更新并关闭连接
      参数:
      sb - 用;分割的sql字符串
      configName -
      rv -
      返回:
    • updateBatchAndClose

      public static String updateBatchAndClose(List<String> sqls, String configName, RequestValue rv)
      批量执行更新并关闭连接
      参数:
      sqls - sql列表
      configName -
      rv -
      返回:
      返回是否错误
    • updateBatchAndCloseTransaction

      public static String updateBatchAndCloseTransaction(List<String> sqls, String configName, RequestValue rv)
      批量执行更新并关闭连接 (Transaction)
      参数:
      sqls - sql列表
      configName -
      rv -
      返回:
      返回是否错误
    • runMultiSqlsAndClose

      public static List<DTTable> runMultiSqlsAndClose(String sqls, String configName, RequestValue rv) throws Exception
      执行混合SQL语句(查询,更新(包含返回自增),存储过程)
      参数:
      sqls -
      configName -
      rv -
      返回:
      返回的所有表
      抛出:
      Exception
    • runMultiSqlsAndClose

      public static List<DTTable> runMultiSqlsAndClose(List<String> listSqls, String configName, RequestValue rv) throws Exception
      执行混合SQL语句(查询,更新(包含返回自增),存储过程)
      参数:
      listSqls -
      configName -
      rv -
      返回:
      返回的所有表
      抛出:
      Exception
    • executeQueryAndReturnTables

      public static List<DTTable> executeQueryAndReturnTables(String sql, String configName, RequestValue rv) throws SQLException
      执行SQL查询返回多条结果集
      参数:
      sql -
      configName -
      rv -
      返回:
      结果集
      抛出:
      SQLException
    • getAutoField

      public static String getAutoField(String sql)
      查找自增的sql的返回字段, 例如 -- auto MEMO_ID
      参数:
      sql -
      返回:
    • checkIsProcdure

      public static boolean checkIsProcdure(String sql)
      检查是否为 存储过程,例如 CALL pr_batAdd(@a)
      参数:
      sql -
      返回:
    • checkIsSelect

      public static boolean checkIsSelect(String sql)
      检查是否为 存储过程,例如 CALL pr_batAdd(@a)
      参数:
      sql -
      返回:
    • checkStartWord

      public static boolean checkStartWord(String sql, String word)
      判断 特定字符出现在非注释的SQL的0位置,多行的SQL只进行第一次判断
      参数:
      sql -
      word - 关键单词,例如SELECT
      返回:
    • removeSqlMuitiComment

      public static String removeSqlMuitiComment(String sql)
      删除sql 的多行备注
      参数:
      sql -
      返回:
    • isComparativeChanges

      public static boolean isComparativeChanges(String sql)
      是否比较更新前和更新后字段的变化, 方式:
      SQL 添加 -- COMPARATIVE_CHANGES
      参数:
      sql -
      返回:
    • getSqls

      public static List<String> getSqls(String sqls)
      将sql混合语句,通过“;”符号,分解为sql列表
      参数:
      sqls -
      返回:
      sql列表
    • getDataBaseName

      public String getDataBaseName()
      数据库名称
      返回:
    • setDataBaseName

      public void setDataBaseName(String dataBaseName)
      数据库名称
      参数:
      dataBaseName -
    • transBegin

      public boolean transBegin()
      开始事务处理
      返回:
    • transCommit

      public boolean transCommit()
      提交事务
      抛出:
      SQLException
    • transRollback

      public void transRollback()
      事务回滚
      抛出:
      SQLException
    • transClose

      public void transClose()
      关闭事务连接
    • getCurrentConfig

      public ConnectionConfig getCurrentConfig()
    • setConfigName

      public void setConfigName(String configName)
    • setConfigName

      public void setConfigName(String configName, String dataBaseName)
      设置数据库连接池句柄
      参数:
      configName -
      dataBaseName -
    • connect

      public boolean connect()
    • executeQueryNoParameter

      public boolean executeQueryNoParameter(String sql)
    • getMoreResults

      public List<DataResult> getMoreResults() throws SQLException
      从执行完的sql中获取更多的结果集
      返回:
      抛出:
      SQLException
    • executeQuery

      public boolean executeQuery(String sql)
      执行查询
      参数:
      sql -
      requestValue -
      返回:
    • executeQueryPage

      public boolean executeQueryPage(String sql, String pkFieldName, int currentPage, int pageSize)
      执行分页查询
      参数:
      sql -
      pkFieldName - 主键名称
      currentPage - 当前页码
      pageSize - 每页记录数
      返回:
    • closeStatment

      public String closeStatment(Statement stmt)
    • batchUpdate

      public void batchUpdate(List<String> sqls, boolean transcation)
      批处理导入数据
      参数:
      sqls -
      transcation -
    • executeMultipleUpdate

      public boolean executeMultipleUpdate(String sql)
      执行多个更新 sql语句,语句用“;”分割,不能在拼接的Sql中有“;”出现
      参数:
      sql -
      返回:
    • executeUpdateBatch

      public int executeUpdateBatch(List<String> sqls)
      批量执行sql语句
      参数:
      sqls -
      返回:
    • executeUpdateBatch

      public int executeUpdateBatch(String sqls)
      批处理执行sql语句,sql语句用 ; 分割
      参数:
      sqls - sql语句用 ; 分割
      返回:
      -1 有错误
    • convertToList

      public List<String> convertToList(String[] sqlArray)
    • runMultiSqls

      public List<DTTable> runMultiSqls(String[] sqlArray) throws Exception
      执行混合SQL语句(查询,更新(包含返回自增),存储过程)
      1. 如果是select返回数据的话,回将第一行数据放到 rv中
      2. 自动创建变量 --auto xxx 会放到rv中
      3. 存储过程返回的结果,带 _OUT参数,例如 ID_OUT 会放到rv中
      参数:
      sqlArray -
      返回:
      select 返回 DTTable集合
      抛出:
      Exception
    • runMultiSqls

      public List<DTTable> runMultiSqls(List<String> listSqls) throws Exception
      执行混合SQL语句(查询,更新(包含返回自增),存储过程)
      1. 如果是select返回数据的话,回将第一行数据放到 rv中
      2. 自动创建变量 --auto xxx 会放到rv中
      3. 存储过程返回的结果,带 _OUT参数,例如 ID_OUT 会放到rv中
      参数:
      listSqls -
      返回:
      抛出:
      Exception
    • executeUpdateReturnAutoIncrementObject

      public Object executeUpdateReturnAutoIncrementObject(String sql)
      执行查询并返回 自动增加值(返回为对象,需要自己判断是int还是long)
      参数:
      sql -
      返回:
    • executeUpdateReturnAutoIncrement

      public int executeUpdateReturnAutoIncrement(String sql)
      执行自增的插入
      参数:
      sql -
      返回:
    • executeUpdate

      public boolean executeUpdate(String sql)
      执行更新
      参数:
      sql -
    • executeUpdateAndReturnChanges

      public UpdateChanges executeUpdateAndReturnChanges(String sql)
      执行更新并返回数据的前后差异
      参数:
      sql -
      返回:
    • executeUpdateNoParameter

      public boolean executeUpdateNoParameter(String sql)
    • getRecordCount

      public int getRecordCount(String sql)
      获取记录数
      参数:
      sql -
      返回:
    • rebuildSql

      public String rebuildSql(String sql) throws Exception
      1. 合成SQL语句,如果参数名为XX_SPLIT,为分割参数,
      例如 select * from users where id in(1,2,3)
      2. SQL语句预替换,即在SQL语句执行前,替换SQL语句本身的参数
      例如 SELECT * FROM ~TB, 如参数TB是 USERS 则替换成 SELECT * FROM USERS
      参数:
      sql -
      requestValue -
      返回:
      抛出:
      Exception
    • clearResultSets

      public void clearResultSets()
      清除所有返回的 resultSet,当长期执行查询的时,会造成内存占用过高 关闭连接会自动执行清除
    • close

      public void close()
      关闭所有连接,包括ResultSet,Cst,Pst
    • getErrorMsg

      public String getErrorMsg()
      Return the error with SQL
      返回:
    • setErrorMsg

      public void setErrorMsg(String errorMessage)
      Manual set conn error message
      参数:
      errorMessage -
    • clearErrorMsg

      public void clearErrorMsg()
      Clear the error
    • executeProcdure

      public HashMap<String,Object> executeProcdure(String callProcduceSql)
      执行存储过程
      参数:
      callProcduceSql - 存储过程调用方法: call pr_some(@name, @id_int_output)
      结尾为_output,表示是输出参数
      _int_output,表示输出参数为整形
      _smallint_output,表示输出参数为小整形
      _tinyint_output,表示输出参数为短整形
      _number_output,_money_output,_numeric_output,_decimal_output表示输出参数为bcd数值
      _long_output/_bigint_output,表示输出参数为长整形
      _text_output/_clob_output,表示输出参数为长文本
      _image_output/_blob_output,表示输出参数为长二进制
      _binary_output/_byte_output,表示输出参数为二进制(varbinary)
      _date_output/_datetime_output/_timestamp_output,表示输出参数为日期时间
      _time_output,表示输出参数为时间
      默认,为varchar字符串
      返回:
      输出参数Map,key转换为大写
    • executeProcdureReturnResults

      public HashMap<String,Object> executeProcdureReturnResults(String callProcduceSql)
      执行存储过程
      参数:
      callProcduceSql - 存储过程调用方法: call pr_some(@name, @id_int_output)
      结尾为_output,表示是输出参数
      _int_output,表示输出参数为整形
      _smallint_output,表示输出参数为小整形
      _tinyint_output,表示输出参数为短整形
      _number_output,_money_output,_numeric_output,_decimal_output表示输出参数为bcd数值
      _long_output/_bigint_output,表示输出参数为长整形
      _text_output/_clob_output,表示输出参数为长文本
      _image_output/_blob_output,表示输出参数为长二进制
      _binary_output/_byte_output,表示输出参数为二进制(varbinary)
      _date_output/_datetime_output/_timestamp_output,表示输出参数为日期时间
      _time_output,表示输出参数为时间
      默认,为varchar字符串
      返回:
      输出参数Map,key转换为大写,
      RS_SIZE 表示返回的结果集数量
      返回的结果集转换为DTTable,名字以RS开头,RS0,RS1,RS2 ...
    • executeProcdureNoParameter

      public void executeProcdureNoParameter(String sql)
      执行存储过程, 不带参数
      参数:
      sql -
      requestValue -
    • sqlParameterStringExp

      public String sqlParameterStringExp(String parameter)
      SQL字符串参数值表达式,替换'号和\转译符号(mysql)
      参数:
      parameter - 字符串参数值
      返回:
    • sqlFieldOrTableExp

      public String sqlFieldOrTableExp(String fieldOrTable)
      处理字段或表名的字符串表达式,带上[(sqlserver)或`(mysql)
      参数:
      fieldOrTable - 字段或表名
      返回:
      带上[(sqlserver)或`(mysql)的字段或表名
    • getConnectionString

      public String getConnectionString()
    • getDatabaseType

      public String getDatabaseType()
    • getDateTimePara

      public String getDateTimePara(String s1)
      获取ListFrame查询的日期表达式
      参数:
      s1 -
      返回:
    • getDateTimePara

      public String getDateTimePara(Timestamp dt)
    • getTimestamp

      public Timestamp getTimestamp(String s1)
      获取sql的timestamp数据
      参数:
      s1 -
      返回:
    • getSchemaName

      public String getSchemaName()
    • getConnection

      public Connection getConnection()
    • setConnection

      public void setConnection(Connection cnn)
    • setCurrentConfig

      public void setCurrentConfig(ConnectionConfig currentConfig)
      参数:
      currentConfig - the _CurrentConfig to set
    • getDebugFrames

      public DebugFrames getDebugFrames()
      返回:
      the _DebugFrames
    • setDebugFrames

      public void setDebugFrames(DebugFrames debugFrames)
      参数:
      debugFrames - the _DebugFrames to set
    • getRequestValue

      public RequestValue getRequestValue()
      返回:
      the _RequestValue
    • setRequestValue

      public void setRequestValue(RequestValue requestValue)
      参数:
      requestValue - the _RequestValue to set
    • getResultSetList

      public com.gdxsoft.easyweb.utils.msnet.MList getResultSetList()
      返回:
      the _ResultSetList
    • getLastResult

      public DataResult getLastResult()
    • isTrans

      public boolean isTrans()
      是否使用事物处理
      返回:
      the _IsTrans
    • getErrorMsgOnly

      public String getErrorMsgOnly()
      Return the error without sql
      返回:
    • getDataHelper

      public DataHelper getDataHelper()
      返回:
      the DataHelper
    • setDataHelper

      public void setDataHelper(DataHelper dataHelper)
      参数:
      dataHelper - the DataHelper to set