Convert mybatis logs into executable sql


This article is copied from

Please pay attention to the original author, favorite and like the original author. The following is an introduction

This tool is a web tool that converts the SQ in the log into executable SQL. You can open it with a browser, as shown below.

However, it does not support conversion into sql for batch insertion

source code

<!DOCTYPE html>
    <meta charset="utf-8">
    <script type="text/javascript">
        function f(obj) {
            var textVa = obj.value;
            // Get SQL statement with question mark
            var statementStartIndex = textVa.indexOf('Preparing: ');
            var statementEndIndex = textVa.length - 1;
            for (var i = statementStartIndex; i < textVa.length; i++) {
                if (textVa[i] == "\n") {
                    statementEndIndex = i;
            var statementStr = textVa.substring(statementStartIndex + "Preparing: ".length, statementEndIndex);
            //get parameters
            var parametersStartIndex = textVa.indexOf('Parameters: ');
            var parametersEndIndex = textVa.length - 1;
            for (var i = parametersStartIndex; i < textVa.length; i++) {
                if (textVa[i] == "\n") {
                    parametersEndIndex = i;
                } else {
            var parametersStr = textVa.substring(parametersStartIndex + "Parameters: ".length, parametersEndIndex);
            parametersStr = parametersStr.split(",");
            for (var i = 0; i < parametersStr.length; i++) {
                // Additional logic will be used if there are parentheses in the data
                tempStr = parametersStr[i].substring(0, parametersStr[i].indexOf("("));
                // get the content in parentheses
                typeStr = parametersStr[i].substring(parametersStr[i].indexOf("(") + 1, parametersStr[i].indexOf(")"));
                // if character type
                if (typeStr == "String" || typeStr == "Timestamp") {
                    statementStr = statementStr.replace("?", "'" + tempStr.trim() + "'");
                } else {
                    // Numeric type
                    statementStr = statementStr.replace("?", tempStr.trim());
            document.getElementById("d1").innerHTML = statementStr;
            return textVa;

        function copySQL() {
            var SQL = document.getElementById("d1");
  ; // select object
            document.execCommand("Copy"); // Execute the browser copy command
            var msg = document.getElementById("msg");
            msg.innerHTML = "copied to clipboard";
            setTimeout(function () {
                msg.innerHTML = "";
            }, 3000);


        function clearLog(obj) {
            obj.value = "";


<h2><font color="#00bfff"> Enter Mybatis SQL log: </font></h2>

<textarea id="sqlLog" rows="13" cols="140" style="font-size:20px"></textarea>

<div style="border:0px deepskyblue solid;width:1425px;height:50px;text-align:right">
    <button style="color:mediumblue;width:100px;height:60px" type="button"
    <button style="color:mediumblue;width:100px;height:60px" type="submit"
        Parse SQL

<h2><font color="#32cd32">Parse to executable SQL:</font></h2>

<textarea id="d1" rows="13" cols="140" style="font-size:20px"></textarea>
<div style="border:0px deepskyblue solid;width:1425px;height:50px;text-align:right">
    <button style="color:mediumblue;width:100px;height:60px" type="button" onclick="copySQL()">copy SQL</button>

<div id="msg"
     style="color:cornflowerblue;border:0px black solid;width:800px;height:20px;text-align:right;font-style: initial;font-size: large">



1. Copy the source code, create a new notepad, paste the source code, and rename the notepad to xx.html format.

2. Copy the SQL log in the Mybatis log. It must be noted that the log must contain the entire contents of Preparing: and Parameters:, and the newline format of the log should be retained. Do not copy it into plain text, just ctrl+c, see the rendering.

3. Open the HTML page with a local browser. After opening the page, paste it into the top text box and click the Parse SQL button. The parsed SQL will appear in the text box below. Click Copy SQL to copy it to the clipboard. At this point, the data can be executed.

Note: If the parameters cannot be filled automatically, please check the SQL log format, whether it is the original format, and whether the original newline is preserved. If not, just copy the log again.


This article is copied from: (116 messages) Free non-cracked mybatis log plugin . Based on this article, page and function optimization has been done.

This article is copied from

In IDEA, there are plug-ins such as mybatis log plgn (charged) or mybatis log (free) that implement this function. You can use plug-ins to implement this function in IDE. When IDEA is not started, you can parse SQL through web pages. Complement each other. If you like this article, please follow the original author, subscribe and like the original author. If the original author minds, please contact to delete, thank you

Posted by skbanta on Sun, 16 Oct 2022 01:32:28 +1030