Java 无效的 SQL 类型:显示 sqlKind = UNINITIALIZED 错误
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/36447240/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Invalid SQL type: sqlKind = UNINITIALIZED error is shown
提问by Mehrab Zaman
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:
这段代码有什么问题?当我尝试更新我的数据时,无效的 SQL 类型:
sqlKind = UNINITIALIZED error is shown.
显示 sqlKind = UNINITIALIZED 错误。
Please help me find solution for my problem.
请帮我找到解决我的问题的方法。
Thank you in advance for answer.
预先感谢您的回答。
回答by Vishal Gajera
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();
回答by Alberto Velasco
回答by Venkata Suresh
Friends,
朋友们,
I too encountered the same issue when I execute a sequence of SQL queries (few queries are commented thru my Java program
当我执行一系列 SQL 查询时,我也遇到了同样的问题(通过我的 Java 程序注释的查询很少
Solution: Remove all commented SQL lines and then execute, you will not get "UNINITIALIED" error any more.
解决方案:删除所有注释的 SQL 行然后执行,您将不会再出现“UNINITIALIED”错误。