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.
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;" ;
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With