How to construct a dynamic String in Java?
<p>I am trying to do something in my Application but I am stuck &amp; unable to find a way forward. Here is my problem:-</p>

<p>I want to create Oracle Queries programatically. 2 such queries for e.g. are DROP TABLE tableName &amp; ALTER TABLE tableName PRIMARY KEY (col1, col2, col3....);</p>

<p>In my class i have created these 2 final static Strings :-</p>

<pre><code>private static final String DROP_TABLE = "DROP TABLE %1$s";

createDropStmt() {
    System.out.format(DROP_TABLE, tableName);
}
</code></pre>

<p>As you can see, this approach will work fine with DROP statements but not with PK's beacuse I don't know how may columns are going to be there till runtime. (private static final String PRIMARY_KEY = "ALTER TABLE %1$s PRIMARY KEY {don't know what to put here}"`)</p>

<p>So, my question is how to do this kind of thing for PK so that my template string can dynamically take values &amp; construct the query.? Does Java have a clean way to do it or my approach should be different?</p>

<p>Thanks</p>
