【发布时间】:2015-10-29 10:46:46
【问题描述】:
我的应用程序出现严重问题。当我登录时,从与数据库的连接到检索信息,一切都很顺利。但是当我想修改我的登录密码时,我不能。我不想要为什么,并且当我连接到 phpmyadmin 时,一切都很好!请帮忙!
try{
Connection con=null;
Statement stmt=null;
ResultSet rs=null;
int m=0;
Class.forName( "com.microsoft.sqlserver.jdbc.SQLServerDriver");
con = DriverManager.getConnection("jdbc:sqlserver://localhost:1433;databaseName=fiche_de_poste;user=sa;password=admin");
stmt = con.createStatement();
rs=stmt.executeQuery("select * from compte");
while(rs.next()){
String hh=jPasswordField2.getText();
String hh2=jPasswordField3.getText();
if(jTextField1.getText().equals(rs.getString("Ncompte"))&&jPasswordField1.getText().equals(rs.getString("Cle"))&&(jPasswordField2.getText().length()>0)&&(jPasswordField3.getText().length()>0)&&(hh.equals(hh2))){
m=1;
try{Connection conMOD2=null;
Statement stmtMOD2=null;
ResultSet rsMOD2=null;
Class.forName(
"com.microsoft.sqlserver.jdbc.SQLServerDriver");System.out.println("1");
conMOD2=DriverManager.getConnection("same as the previous one");
System.out.println("1");
stmtMOD2 = conMOD2.createStatement();
System.out.println("1");
String reqq="Update compte set Cle='"+jPasswordField3.getText()+"' WHERE
Ncompte='"+jTextField1.getText()+"'";
System.out.println("2");
System.out.println(reqq);
PSUpdate = conMOD2.prepareStatement(reqq);
PSUpdate.executeUpdate();
//rsMOD2=stmtMOD2.executeQuery(reqq);
JOptionPane.showMessageDialog(null, " Mot de passe modifié avec succès
!!");
}catch(Exception ex){}
}
}
if (m==0)
JOptionPane.showMessageDialog(null, "ID ou mot de passe non valide,ou bien un des champs es vide");
}catch(Exception ex){
JOptionPane.showMessageDialog(null, "Ops , Impossible de se connecter à la base de données !");
}
【问题讨论】:
-
在发布之前美化(格式化)代码。什么是 "conMOD2=DriverManager.getConnection("same as the previous one"); "你的代码中真的有它吗?你得到什么错误信息?
-
不,我有一个和上一个一样的。我在发布时遇到了问题,这就是我删除它的原因;)
-
在 SQL UPDATE 中有一个错误。字段 Ncompte 是文本类型。无法使用运算符“=”比较文本字段。将 sql 查询更改为
UPDATE compte SET Cle = ? WHERE Ncompte LIKE ?。请参阅下面的答案,该答案说明了您的问题的有效解决方案。
标签: java sql-server netbeans