Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


prabhu
java
1 Answer(s)      5 years and a month ago
Posted in : Java Beginners



Advertisement
View Answers

December 12, 2009 at 10:34 AM


Hi Friend,

Yes, you can. We are providing you the code for Change Password through which we have retrieved the id of particular password using select query and then using this id we have changed the existed password.

import java.sql.*;
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;

public class ChangePassword extends JFrame{
JLabel label1,label2,label3;
JPasswordField text1,text2,text3;
JButton button;
static JPanel panel;
String connectionURL = "jdbc:mysql://localhost:3306/test";;;
Connection con;
public ChangePassword(){

label1=new JLabel("Old Password");
label2=new JLabel("New Password");
label3=new JLabel("Confirm Password");
text1=new JPasswordField(10);
text2=new JPasswordField(10);
text3=new JPasswordField(10);
button=new JButton("Change Password");
panel=new JPanel(new GridLayout(4,2));
panel.add(label1);
panel.add(text1);
panel.add(label2);
panel.add(text2);
panel.add(label3);
panel.add(text3);
panel.add(button);


button.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
String value1=text1.getText();
String value2=text2.getText();
String value3=text3.getText();
try{
Class.forName("com.mysql.jdbc.Driver");
con = DriverManager.getConnection(connectionURL, "root", "root");
Statement st=con.createStatement();
ResultSet rs=st.executeQuery("Select id from login where password='"+value1+"'");
int id=0;
if(rs.next()){
id=rs.getInt("id");
}
else{
JOptionPane.showMessageDialog(null, "Invalid Password!", "Error", JOptionPane.ERROR_MESSAGE);
}
st.close();
if(value2.equals(value3)){
Statement st1=con.createStatement();
int i=st1.executeUpdate("update login set password='"+value2+"' where id='"+id+"'");
JOptionPane.showMessageDialog(null,"Your password is changed successfully.");
st1.close();
con.close();
}

else{
JOptionPane.showMessageDialog(null, "Invalid Confirm Password!", "Error", JOptionPane.ERROR_MESSAGE);
}
}
catch(Exception exc){
System.out.println(exc);
}
}
});
}
public static void main(String[] args){
ChangePassword pass=new ChangePassword();
pass.setVisible(true);
pass.setSize(300,100);
pass.add(panel);
}
}

Thanks


Related Tutorials/Questions & Answers:
java
java  diff bt core java and java
java
java  what is java
Advertisements
Java
Java   Whether Java is pure object oriented Language
java
java  different between java & core java
java
java  explain technologies are used in java now days and structure java
java
java   why iterator in java if we for loop
JAVA
JAVA  how the name came for java language as "JAVA
java
java  what is java reflection
java
java  is java open source
java
what is the size of array in java ?  what is the size of array in java ? what is the mean of finalize in java
java
java   in java does not pointers concept but what is nullpointers in java?   nullpointer is a runtime Exception
java
java  write a java program using filenotfoundexception
java
java   difference between class and interface
java
java  why multiple inheritance is not possible in java
java
java  is java purely object oriented language
java
java  how use java method
java
java  send me java interview questions
java
java  write a program in java to acess the email
java
java  Write a java code to print "ABABBABCABABBA
java
java  why to set classpath in java
java
java  why to set classpath in java
java
java  why to set classpath in java
java
java  give a simple example for inheritance in java
Java
Java  how to do java in command prompt
java
java  sample code for RARP using java
java
java  RARP implementation using java socket
Java
Java  how to draw class diagrams in java
java
java  explain object oriented concept in java
Java
Java   Whether Java is Programming Language or it is SOftware
java
java  what are JAVA applications development tools
java
java  why to set classpath in java
 

 

 

DMCA.com