0

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?

1 Answer 1

1

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))");
Sign up to request clarification or add additional context in comments.

1 Comment

thank you, I was aware of this and was wondering if spring implemented something similar...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.