Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>First thing what you want to fix is please don't use <code>String</code> instance when you want to change it. <code>String</code> intance is immutable and when you modify already created <code>String</code>, new modified instance is created and it is not free. You should to use <code>StringBuilder</code> for this that have instance methods which allow to modify it without need to create new instance. I recommend to you use always <code>StringBuilder</code> when you modifying <code>String</code>. and second so you call <code>con.prepareStatement(sql)</code> and then you modify its sql field. it's not good is't? So only add it after your work with String.</p> <pre><code>String sql = "CREATE TABLE if not exists itemset (?"; for(int j=1; j &lt; ccolumns; j++) { sql += ",?"; } sql += ")"; System.out.println(sql); up1 = con.prepareStatement(sql); for(int j=1; j &lt; ccolumns+1; j++) { System.out.println(j); up1.setString(j, "item"+j+" TINYINT(10)"); } up1.executeQuery(); </code></pre> <p>You cannot call <code>prepareStatement</code> with given <code>String</code> and then modify it.</p> <hr> <p>But more cleaner and faster try to do it like this</p> <pre><code>StringBuilder sqlStatement = new StringBuilder( "CREATE TABLE if not exists itemset (?"); for(int j=1; j &lt; ccolumns; j++) { sqlStatement.append(",?"); } sqlStatement.append(")"); up1 = con.prepareStatement(sqlStatement.toString()); for(int j=1; j &lt; ccolumns+1; j++) { System.out.println(j); up1.setString(j, "item"+j+" TINYINT(10)"); } up1.executeQuery(); </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload