Invalid SQL type: sqlKind = UNINITIALIZED error is shown
Asked Answered
G

5

5
    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.

Gibbosity answered 6/4, 2016 at 9:40 Comment(2)
You are missing to add a space between your query parts : " UPDATE...etc.. Your query actually begins with BEGINUPDATE as it is. Consider printing your sql String to see what's wrong.Apply
faced the same issue in IntelliJ. IntelliJ highlights the keywords like "Update", "AND", "FROM" in blue and if it is not highlighted then you know there is a space required in the previous line before the keyword.Rachele
F
9

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;" ;
Faustena answered 21/9, 2016 at 7:38 Comment(0)
C
3

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.

Curious answered 27/5, 2019 at 20:26 Comment(1)
I received this exact error when executing the SQL Advisor. Removing the comments from the query did the trick. Thanks.Auvil
M
2

You can do something likewise,

String sql = "UPDATE LOGIN SET USERNAME = ?, PASSWORD = ?, NAME = ? WHERE USERNAME = ?" 

PreparedStatement preparedStatement = dbConnection.prepareStatement(sql);
preparedStatement .setString(1, UsernameText4.getText());
preparedStatement .setString(2, PasswordText4.getText());
preparedStatement .setString(3, NameText4.getText());
preparedStatement .setString(4, jLabel16.getText());

preparedStatement .executeUpdate();
....
dbConnection.commit();
Myrmidon answered 6/4, 2016 at 9:49 Comment(0)
B
1

I faced this error in CloudBeaver while executing PL/SQL script through "Execute SQL Script". It did not like the ending slash "/".

Brickkiln answered 19/12, 2023 at 11:47 Comment(0)
S
0

java.sql.sqlexception: Invalid SQL type: sqlKind = UNINITIALIZED

This error occurs when there is syntax error. check your syntax, Print the query and run the same query on your SQL client tool like SQL Developer, Toad, DBeaver..,

Example: consider below is the o/p of Sysout

[select * from dual] & ["select * from dual"] //sqlKind = UNINITIALIZED

select * from dual // This is good

Note all three queries run, but first two needs to be replace and []"" has to be removed before sending it for execution.

Siobhan answered 2/11, 2020 at 5:55 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.