Frage

Currently, I'm testing some stored procedures in JAVA on oracle db, so I tried to display all the emp entities.

So my question is how can I display a whole table throught a java stored procedure?

This is what i tried:

create or replace and compile java source named getEMP
as
import java.sql.*;
import java.util.*;
public class Example{
    public static void showEmp() throws SQLException, ClassNotFoundException {
            ResultSet rs;
            Properties p = new Properties();
            p.put("user", "user");
            p.put("password","password");
            String strCon = "Connection String";

            Class.forName("oracle.jdbc.OracleDriver"); 
            Connection con = DriverManager.getConnection(strCon, p);

            Statement stmt;

            con = DriverManager.getConnection(strCon, p);
            String query =
                    "select empno, ename, deptno, sal, comm " +
                    "from emp";

            stmt = con.createStatement();
            rs = stmt.executeQuery(query);

        //Display the ResultSet
    }
}

My problem in this methode is that i can't use System.out.println("");. It just displays nothing after this:

create or replace procedure showEmp
as language java name 'Example.showEmp()';

exec showEmp;

Thanks in advance!

War es hilfreich?

Lösung

You need to make sure that server output is enabled and also to redirect java output to it. In SQL*PLus you can accomplish that with the following two statements:

SQL> set serveroutput on;
SQL> call dbms_java.set_output(20000);

The number 20000 is the maximum buffer size, same as in DBMS_OUTPUT.

After this if you run exec showEmp; you should be able to see the results of a System.out.println() call being printed out.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top