I am trying to print the plsql variable value (l_console_message) in Java. However, this approach doesn't seem to be working. I belive that something goes wrong at ResultSet bit. I am missing something here. Any idea, what goes wrong?
PreparedStatement statement = null;
try {
statement = connection.prepareStatement("\n" +
" declare " + "\n" +
" p_schema_name varchar2(400):= upper('" + schema + "'); " + "\n" +
" p_temp_table_name varchar2(400) := upper('temp_table_jobs_name'); " + "\n" +
" l_result varchar2(400); " + "\n" +
" l_owner varchar2(200); " + "\n" +
" l_job_name varchar2(200); " + "\n" +
" l_enabled varchar2(200); " + "\n" +
" l_console_message varchar2(4000); " + "\n" +
" cursor c1_temp_table_name is " + "\n" +
" select " + "\n" +
" table_name " + "\n" +
" from all_tables " + "\n" +
" where table_name = p_temp_table_name; " + "\n" +
" begin " + "\n" +
" open c1_temp_table_name; " + "\n" +
" fetch c1_temp_table_name into l_result; " + "\n" +
" if c1_temp_table_name %notfound then " + "\n" +
" execute immediate ' " + "\n" +
" create table '||p_schema_name||'.'||p_temp_table_name||' ( " + "\n" +
" schema_name varchar2 (1000), " + "\n" +
" job_name varchar2(1000), " + "\n" +
" status varchar2(100) " + "\n" +
" )'; " + "\n" +
" l_console_message := p_temp_table_name||' created.'; " + "\n" +
" dbms_output.put_line (l_console_message); " + "\n" +
" end if; " + "\n" +
" close c1_temp_table_name; " + "\n" +
" exception when others then " + "\n" +
" null; " + "\n" +
" end;");
ResultSet rs = statement.execute();
while (rs.next()){
System.out.println(rs.getString(l_console_message));
}
}
catch (SQLException e) {
System.out.println("ERROR: Unable to run SQL statements for schema " + schema + " in beforeMigrate: " + e.getMessage());
}
finally {
if (null != statement) {
try {
statement.close();
}
catch (SQLException se) {
System.out.println("ERROR: Unable to close statement in beforeMigrate: " + se.getMessage());
}
}
}
Thanks in advance :-)