SQL语句中占位符的替换,界面如下;
代码如下:
<script> //Created:2012-6-9 function bind() { if(parameters.value && preparedStmt.value) { //reset notice noticeArea.innerText=""; //replace special character var reg=new RegExp("\r\n","g"); var paramArray = parameters.value.replace(reg,"").split(parameterSep.value); nativeSQL.value = preparedStmt.value; //foreach for(var i=0;i<paramArray.length;i++) { nativeSQL.value = nativeSQL.value.replace("?","'"+paramArray[i]+"'"); } if(nativeSQL.value.indexOf("?") != -1) { noticeArea.innerText="Not all placeholder be binded !"; } } } </script> <h2 style="color:blue" align="center">Bind parameters for prepared SQL statement </h2> <table align="center"> <tr> <td>Parameter Separater:</td> <td><input id="parameterSep" value=","> <span id="noticeArea" style="color:red"></span></td> </tr> <tr> <td>Prepared Statement:</td> <td><textarea id="preparedStmt" cols=100% rows=7></textarea></td> </tr> <tr> <td>Parameters:</td> <td><textarea id="parameters" cols=100% rows=3></textarea></td> </tr> <tr> <td>Native SQL:</td> <td><textarea id="nativeSQL" cols=100% rows=10 style="color:blue"></textarea></td> </tr> <tr> <td colspan=2 align="center"><input type="button" value="Bind" onclick="bind();"></td> </tr></table>