Here you are:
The output should be:
Why the INSERT in this code fails?
Because the insertSQL is a GString. if you make it a String like this
it will work. Or you can do it like this:
In the last code snippet, GSQL will automatically create a prepared statement for you and run it.
I modified the code to get it to work with Oracle and for readability.
The Sql.newInstance will connect to an Oracle database SID called XE installed on localhost
at port 1521. The database user is "username" and the password is "password".
In order to get this to work you will have to install the the latest jdbc.jar file from Oracle's website. You need to install the .jar file into the
lib directory in your GROOVY_HOME directory:
The code does the following:
1. Creates TableA in username's schema
2. Inserts a row into TableA
3. Performs a SELECT * FROM TableA;
4. Returns "TableA row: Bill Lyons"