Subject Re: DDL Scripts
Author Roman Rokytskyy
> I need an application to manage my production database, in order to
> insert some client's data every time I get a new client. There is no
> problem on it. Besides, I need to create some per client specific
> tables in the same process. So I need to execute DDL scripts within
> my manager java application.
> Is this really a very strange situation?

No. My applications generates all tables and procedures on the fly.

> Anyway, how should I best do it?

JayBird does not have a separate component to execute scripts.
However, you can easily write your own. Only keep in mind that usually
Firebird scripts contain following "control commands":

- "SET NAMES XXXX;" can happen only on the begining of the script, set
the lc_ctype property of the connection accordingly;
- "COMMIT;" and "COMMIT WORK;"; commit.
- "SET TERM XXXYYYY"; change current terminating character sequence
from YYY to XXX, default statement terminating sequence is ";"
- if statement to execute is DDL statement(i.e. starts with "CREATE",
"ALTER" or "DROP"), commit after executing it (unless script contains

Then you simply parse your script, split it into the statements and
execute using normal java.sql.Statement instance:

Properties props = new Properties();
props.setProperty("user", "sysdba");
props.setProperty("password", "masterkey");

MyFirebirdScriptTokenizer st = new MyFirebirdScriptTokenizer(script);

if (st.getNames() != null)
props.setProperty("lc_ctype", st.getNames());

Connection con = DriverManager.getConnection(myUrl, props);
Statement stmt = con.createStatement();

while(st.hasMoreTokens()) {
String sql = st.nextToken();
if (isDDL(sql)) {
con.commit(); // commit previous statements
} else


Best regards,
Roman Rokytskyy