我有一個嚴重的問題,我的應用程序。當我登錄一切順利從數據庫連接檢索information.but當我想修改我的登錄密碼我can't.i不要爲什麼,當我連接到phpmyadmin一切都很棒!請幫忙 !SQL服務器更新查詢與Java NetBeans
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(與前一個相同」);「你真的在你的代碼中有嗎?你得到什麼錯誤信息? – Willmore
不,我有一個像以前one.i有問題發佈這就是爲什麼我刪除它;) – jhon
在SQL UPDATE中有一個錯誤。字段Ncompte是文本類型。文本字段不能使用運算符「=」進行比較。將sql查詢更改爲'UPDATE compte SET Cle =?在哪裏Ncompte喜歡?'。請參閱下面的答案,說明您的問題的工作解決方案。 – Willmore