1

I am running a database and trying to do all data handling through PS/SQL, and the thing is that once I establish the connection, I have this code, but it fails with the error of

SQLException:Invalid SQL type: sqlKind = UNINITIALIZED

The reason why I am executing it in java is because my assignment tells me that java will handle some things (that I haven't included here), but as for everything else (data manipulation and error checking), it must be handled by oracle. Honestly this harsh restriction sounds silly to me.

The intent of the code below is to read user input via an anonymous block and then print it to the DBMS output, though I'm not sure if that is even possible. Can anyone help me to fix this?

try {
            CallableStatement cs = dbConnection.prepareCall("" +
                    "DECLARE" +
                    "myMessage varchar2 (20);" +
                    "BEGIN" +
                    "myMessage := '&myMessage';" +
                    "DBMS_OUTPUT.PUT_LINE(myMessage);" +
                    "END;");
            cs.execute();

        } catch (SQLException x) {
            System.out.println("SQLException:" + x.getMessage());
        }
5
  • 1
    The "variable" replacement using & is a SQLPlus feature and done on the client. The server can never accept input from a user who is sitting at a different computer. You *must prompt the user for input through your Java program. PL/SQL never interacts with the end user.
    – user330315
    Nov 25, 2013 at 19:29
  • That is the sort of confirmation I needed. I had my suspicions about it already. Thank you so much.
    – Ren
    Nov 25, 2013 at 19:31
  • Just draw a picture which piece of code runs on which computer - then it will become evident.
    – user330315
    Nov 25, 2013 at 19:34
  • For the record; I've seen the same error when erroneously pushing an empty SQL-string on Oracle.
    – thoredge
    Mar 26, 2015 at 11:33
  • IMHO @a_horse_with_no_name has provided the answer in his comment. It's just not possible by design. Jan 26, 2016 at 11:17

0

Your Answer

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

Browse other questions tagged or ask your own question.