hi friends,
i was trying one java program, which gets the username and password from the user and has to check them if they r present in the database (MySQL) and has to give the result as soon as the OK button has been clicked..
i've created the GUI interface using eclipse and database in MySQL. My prob is that, i want to grab the text from the both text boxes, and have to search in MySQL with the texts typed in the text boxes.
i've used 3 classes, one for getting n setting the user id and password to MySQL, another one is for connecting the java and MySQL and the final is for GUI..
--> this is a function which i used in the 2nd class.. here, i pass the 3rd class's object to this function
public boolean UsrAuthPw(UsrVerf uv){
boolean status = false;
try{
Connection con = getconnect();
Statement s = con.createStatement();
String s1 = uv.t1.getText();
String s2 = uv.t2.getText();
ResultSet rs = s.executeQuery("SELECT UserId, Password from usrauth where UserId = ' "+s1+" ' and Password = ' "+s2+"' ");
System.out.println("UserId = '"+s1+"' and Password = '"+s2+"");
while (rs.next()){
System.out.println("1234");
status = true;
}
}
catch(java.sql.SQLException sqlexcp){
sqlexcp.printStackTrace();
System.out.println("SQL Exception");
status = false;
}
return status;
}
--> this is the main function of the 3rd class..
public static void main(String args[]){
JFrame frame = new JFrame("User Authentication");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
UsrVerf uv = new UsrVerf();
UsrConn uc = new UsrConn();
boolean status = false;
uc.getconnect();
uv.panelaction(frame);
uc.UsrAuthPw(uv);
if (status == true){
System.out.println("12345");
}else {
System.out.println("123456");
}
frame.pack();
frame.setVisible(true);
}
--> this wat i gave for the action to be done as soon as, the button is pressed..
public void actionPerformed(ActionEvent e){
String s1 = t1.getText();
String s2 = t2.getText();
if (s1.equals(s2)){
l3.setText("Both are same");
} else {
l3.setText("Processing....");
}
}
when i run the prog, i'm getting the GUI and if i give the correct user id and password, the output is like this..
UserId = ' ' and Password = ' '
123456
am i correct with this one..
can anyone get me clear..