Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Invalid SQL type: sqlKind = UNINITIALIZED error is shown

Tags:

java

oracle

plsql

    String s1 = PasswordText4.getText();
    String s2 = ConfirmText4.getText();
    String s3 = NameText4.getText();
    String s4 = UsernameText4.getText();
    String s5 = jLabel16.getText();

    if (PasswordText4.getText().equals(ConfirmText4.getText()) && s1.length() != 0 && s3.length() != 0 && s1.length() >= 4 && s2.length() >= 4) {
        try {
            String sql
                    = "BEGIN"
                    + "UPDATE LOGIN SET USERNAME = ?, PASSWORD = ?, NAME = ?"
                    + "WHERE USERNAME = ?;"
                    + "commit;"
                    + "END;";
            CallableStatement cstmt = conn.prepareCall(sql);
            cstmt.setString(1, UsernameText4.getText());
            cstmt.setString(2, PasswordText4.getText());
            cstmt.setString(3, NameText4.getText());
            cstmt.setString(4, jLabel16.getText());

            //System.out.println(jLabel16.getText());

            int dialogButton = JOptionPane.YES_NO_OPTION;
            int dialogResult = JOptionPane.showConfirmDialog(null, "Are you sure you want to update?", "Warning", dialogButton);
            if (dialogResult == JOptionPane.YES_OPTION) {
                cstmt.execute();
                JOptionPane.showMessageDialog(null, "Information Updated");
                jLabel15.setText(NameText4.getText());
                jLabel16.setText(UsernameText4.getText());
                jLabel17.setText(PasswordText4.getText());
            }

        } catch (Exception e) {
            JOptionPane.showMessageDialog(null, e);
        }
    }

What's wrong with this code? When I try to update my data, the Invalid SQL type:

sqlKind = UNINITIALIZED error is shown.

Please help me find solution for my problem.

Thank you in advance for answer.

like image 660
Mehrab Zaman Avatar asked Apr 06 '16 09:04

Mehrab Zaman


2 Answers

Berger is right, you need to add spaces between your query parts, for example:

String sql = " BEGIN "
           + " UPDATE LOGIN SET USERNAME = ?, PASSWORD = ?, NAME = ? "
           + " WHERE USERNAME = ?; "
           + " commit; "
           + " END;" ;
like image 193
Alberto Velasco Avatar answered Nov 15 '22 02:11

Alberto Velasco


Friends,

I too encountered the same issue when I execute a sequence of SQL queries (few queries are commented thru my Java program

Solution: Remove all commented SQL lines and then execute, you will not get "UNINITIALIED" error any more.

like image 24
Venkata Suresh Avatar answered Nov 15 '22 02:11

Venkata Suresh