zuloo
zuloo

Reputation: 1330

mysql create procedure with spring framework in java

I understood how to call a stored procedure with spring. is there a way to create a procedure from within java using spring, executing it and delete it afterwards, or have this procedures to be created before using the mysql-console?

Upvotes: 0

Views: 242

Answers (1)

bpgergo
bpgergo

Reputation: 16037

It is possible to run DDL statements from JDBC (which is under the hood when you use Spring).

See an example here of dropping and creating a table: http://dev.mysql.com/doc/refman/5.0/es/connector-j-usagenotes-basic.html#connector-j-usagenotes-last-insert-id

stmt = conn.createStatement(java.sql.ResultSet.TYPE_FORWARD_ONLY,
                            java.sql.ResultSet.CONCUR_UPDATABLE);
stmt.executeUpdate("DROP TABLE IF EXISTS autoIncTutorial");
stmt.executeUpdate(
        "CREATE TABLE autoIncTutorial ("
        + "priKey INT NOT NULL AUTO_INCREMENT, "
        + "dataField VARCHAR(64), PRIMARY KEY (priKey))");

Upvotes: 1

Related Questions