gpt4 book ai didi

java - 使用netbeans在java中更改密码程序

转载 作者:行者123 更新时间:2023-12-02 07:08:03 24 4
gpt4 key购买 nike

经过一番大惊小怪,我使用了 JAVA DB,现在使用 apache Derby 客户端驱动程序来使用,最终进入我的数据库后,我遇到了一个新问题

 private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                         
String uname = jTextField1.getText();
String strpass = jPasswordField1.getText();
String newpass = jPasswordField2.getText();
String conpass = jPasswordField3.getText();

try
{
DriverManager.registerDriver(new org.apache.derby.jdbc.EmbeddedDriver());
}
catch(SQLException ex1)
{
ex1.printStackTrace();
}

try
{

Class.forName("org.apache.derby.jdbc.ClientDriver");
}
catch(ClassNotFoundException ex)
{
ex.printStackTrace();
}
try
{
Connection con = DriverManager.getConnection("jdbc:derby://localhost:1527/niiitusers");
Statement st = con.createStatement();
ResultSet rs = st.executeQuery("Select * from app.userlogin");
while(rs.next())
{
String usrname = rs.getString("username");
String passwd = rs.getString("password");
if(uname.equals(usrname) && strpass.equals(passwd))
{

if(newpass.equals(conpass))
{
Statement st1 = con.createStatement();
ResultSet i = st1.executeQuery("UPDATE app.userlogin SET password='newpass' where username='usname'");//query i am using to update the password
JOptionPane.showMessageDialog(null, "PASSWORD UPDATE SUCCESSFUL");

}

else
{
JOptionPane.showMessageDialog(null, "PLEASE CONFIRM PASSWORD");
}}
else if(uname.equals("") && strpass.equals("") && newpass.equals(""))
{
JOptionPane.showMessageDialog(null, "PLEASE ENTER ALL INFORMATION");
}
else
{
JOptionPane.showMessageDialog(null, "USERNAME NOT FOUND");
}
st.close();

con.close();
}

}
catch(SQLException e)
{
e.printStackTrace();
}



}

java.sql.SQLException: executeQuery method can not be used for update.
at org.apache.derby.client.am.SQLExceptionFactory40.getSQLException(Unknown Source)
at org.apache.derby.client.am.SqlException.getSQLException(Unknown Source)
at org.apache.derby.client.am.Statement.executeQuery(Unknown Source)

它不执行更新操作。不知道问题出在哪里

最佳答案

它没有显示任何输出,因为您的 catch block 中没有任何内容。

首先,这需要改变......

catch (SQLException ex) {
e.printStackTrace();
} }

其次,我会查看显而易见的内容,您是否使用了正确的凭据?数据库的 IP 地址是否正确?

无论哪种方式,堆栈跟踪都会为您提供所需的答案。

关于java - 使用netbeans在java中更改密码程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15862832/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com