You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

sql.html 4.7 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. <html>
  2. <head>
  3. </head>
  4. <body>
  5. <h2><a name="sql">Sql</a></h2>
  6. <h3>Description</h3>
  7. <p>Executes a series of sql statement via JDBC to a database. Statements can either be read in from a text file using the src attribute or from between the enclosing sql tags.</p>
  8. <p>Multiple statements can be set and each statement is delimited from the next use a semi-colon. Individual lines within the statements can be commented using either -- or // at the start of the line.</p>
  9. <p>The auto-commit attribute specifies whether auto commit should be turned on or off whilst executing the statements. If auto-commit is turned on each statement will be executed and commited. If it is turned off the statements will all be executed as one transaction.</p>
  10. <h3>Parameters</h3>
  11. <table border="1" cellpadding="2" cellspacing="0">
  12. <tr>
  13. <td width="12%" valign="top"><b>Attribute</b></td>
  14. <td width="78%" valign="top"><b>Description</b></td>
  15. <td width="10%" valign="top"><b>Required</b></td>
  16. </tr>
  17. <tr>
  18. <td width="12%" valign="top">driver</td>
  19. <td width="78%" valign="top">Class name of the jdbc driver</td>
  20. <td width="10%" valign="top">Yes</td>
  21. </tr>
  22. <tr>
  23. <td width="12%" valign="top">url</td>
  24. <td width="78%" valign="top">Database connection url</td>
  25. <td width="10%" valign="top">Yes</td>
  26. </tr>
  27. <tr>
  28. <td width="12%" valign="top">userid</td>
  29. <td width="78%" valign="top">Database user name</td>
  30. <td width="10%" valign="top">Yes</td>
  31. </tr>
  32. <tr>
  33. <td width="12%" valign="top">password</td>
  34. <td width="78%" valign="top">Database password</td>
  35. <td width="10%" valign="top">Yes</td>
  36. </tr>
  37. <tr>
  38. <td width="12%" valign="top">src</td>
  39. <td width="78%" valign="top">File containing sql statements</td>
  40. <td width="10%" valign="top">Yes, unless statements enclosed within tags</td>
  41. </tr>
  42. <tr>
  43. <td width="12%" valign="top">autocommit</td>
  44. <td width="78%" valign="top">Auto commit flag for database connection (default false)</td>
  45. <td width="10%" valign="top">No, default "false"</td>
  46. </tr>
  47. <tr>
  48. <td width="12%" valign="top">print</td>
  49. <td width="78%" valign="top">Print result sets from the statements (default false)</td>
  50. <td width="10%" valign="top">No, default "false"</td>
  51. </tr>
  52. <tr>
  53. <td width="12%" valign="top">showheaders</td>
  54. <td width="78%" valign="top">Print headers for result sets from the statements (default true)</td>
  55. <td width="10%" valign="top">No, default "true"</td>
  56. </tr>
  57. <tr>
  58. <td width="12%" valign="top">output</td>
  59. <td width="78%" valign="top">Output file for result sets (defaults to System.out)</td>
  60. <td width="10%" valign="top">No (print to System.out by default)</td>
  61. </tr>
  62. <tr>
  63. <td width="12%" valign="top">classpath</td>
  64. <td width="78%" valign="top">Classpath used to load driver</td>
  65. <td width="10%" valign="top">No (use system classpath)</td>
  66. </tr>
  67. </table>
  68. <h3>Examples</h3>
  69. <pre><blockquote>&lt;sql
  70. driver="org.database.jdbcDriver"
  71. url="jdbc:database-url"
  72. userid="sa"
  73. password="pass"
  74. src="data.sql"
  75. /&gt;
  76. </pre></blockquote>
  77. <p>Connects to the database given in url as the sa user using the org.database.jdbcDriver and executes the sql statements contained within the file data.sql</p>
  78. <blockquote><pre>&lt;sql
  79. driver="org.database.jdbcDriver"
  80. url="jdbc:database-url"
  81. userid="sa"
  82. password="pass"
  83. &gt;
  84. insert
  85. into table some_table
  86. values(1,2,3,4);
  87. truncate table some_other_table;
  88. &lt;/sql&gt;
  89. </pre></blockquote>
  90. <p>Connects to the database given in url as the sa user using the org.database.jdbcDriver and executes the two sql statements inserting data into some_table and truncating some_other_table</p>
  91. <p>Note that you may want to enclose your statements in
  92. <code>&lt;![CDATA[</code> ... <code>]]&gt;</code> sections so you don't
  93. need to escape <code>&lt;</code>, <code>&gt;</code> <code>&amp;</code>
  94. or other special characters. For example:</p>
  95. <blockquote><pre>&lt;sql
  96. driver="org.database.jdbcDriver"
  97. url="jdbc:database-url"
  98. userid="sa"
  99. password="pass"
  100. &gt;&lt;![CDATA[
  101. update some_table set column1 = column1 + 1 where column2 &lt; 42;
  102. ]]&gt;&lt;/sql&gt;
  103. </pre></blockquote>
  104. <p>The following connects to the database given in url as the sa user using the org.database.jdbcDriver and executes the sql statements contained within the file data.sql, with output piped to outputfile.txt, searching /some/jdbc.jar as well as the system classpath for the driver class.</p>
  105. <pre><blockquote>&lt;sql
  106. driver="org.database.jdbcDriver"
  107. url="jdbc:database-url"
  108. userid="sa"
  109. password="pass"
  110. src="data.sql"
  111. print="yes"
  112. output="outputfile.txt"
  113. &gt;
  114. &lt;classpath&gt;
  115. &lt;pathelement location="/some/jdbc.jar"&gt;
  116. &lt;/classpath&gt;
  117. &lt;/sql&gt;
  118. </pre></blockquote>
  119. </body>
  120. </html>