Code used in video "Java prog#3. Login Program for Netbeans java with sqlite [ Mysql ] database PART-1" and "Java prog#3. Login Program for Netbeans java with sqlite [ Mysql ] database PART-2"

Here I am providing the downloadable code link of  the java code I have used in the video
 " "Java prog#3. Login Program for Netbeans java with sqlite [ Mysql ] database PART-1" and  "Java prog#3. Login Program for Netbeans java with sqlite [ Mysql ] database PART-2""  of my YouTube channel ProgrammingKnowledge


Click Link to watch the video LINK


This code below is for the Login button action perform


    private void cmd_loginActionPerformed(java.awt.event.ActionEvent evt) {
        // TODO add your handling code here:
String sql ="select * from Empoyeeinfo where username=? and password=?";
try{
pst=conn.prepareStatement(sql);
pst.setString(1,txt_username.getText());
pst.setString(2,txt_password.getText());
//////////////////////////////////////////////
///////////
rs=pst.executeQuery();
if(rs.next()){
JOptionPane.showMessageDialog(null, "Username and Password is correct ");
rs.close();
pst.close();
close();
Employee_info s =new Employee_info();
s.setVisible(true);

}
else{
JOptionPane.showMessageDialog(null, "Username and Password is not correct");


}
}
catch(Exception e)
{
JOptionPane.showMessageDialog(null, e);

} finally {
try{
rs.close();
pst.close();

}
catch(Exception e) {
}
}
}


If you have question in mind that  How can we give roles between the manager and the rest of the users...............then follow the code below.... This code below is for the Login button action perform for  the manager and the rest of the users.....



 private void cmd_loginActionPerformed(java.awt.event.ActionEvent evt) {
try{

int count=0;

String sql="select * from employee_data where username =? and userpassword =? and Division =? ";

pst =conn.prepareStatement(sql);



pst.setString(1, txt_username.getText());
pst.setString(2, txt_password.getText());



pst.setString(3, txt_userlevel.getSelectedItem().toString());

rs=pst.executeQuery();



//query for welcome name
{
}
while(rs.next()){



count=count+1;

}

String division= (txt_userlevel.getSelectedItem().toString());

if(division=="Top") {


if(count==1){

JOptionPane.showMessageDialog(null, "Username and password correct");

User_JFrame p= new User_JFrame();

//Admin_HR_JFrame p = new Admin_HR_JFrame();

p.setVisible(true);

close();

}

else if(count>1){

JOptionPane.showMessageDialog(null, "Duplicate user and password Access denied");
// Level_1_JForm s = new Level_1_JForm();

//s.setVisible(true);

}

else{

JOptionPane.showMessageDialog(null, "Username and password not correct");

}

}

else if(division=="Manager"){

if(count==1){

JOptionPane.showMessageDialog(null, "Username and password correct");


Competency_Form_JFrame s = new Competency_Form_JFrame();

s.setVisible(true);

close();

}

else if(count>1){

JOptionPane.showMessageDialog(null, "Duplicate user and password Access denied");
// Level_1_JForm s = new Level_1_JForm();



//s.setVisible(true);



}



else{



JOptionPane.showMessageDialog(null, "Username and password not correct");

}

}

else if(division=="Executive"){

if(count==1){

JOptionPane.showMessageDialog(null, "Username and password correct");

Competency_Form_JFrame s = new Competency_Form_JFrame();



s.setVisible(true);

close();

}

else if(count>1){

JOptionPane.showMessageDialog(null, "Duplicate user and password Access denied");

//Level_1_JForm s = new Level_1_JForm();



//s.setVisible(true);

}

else{

JOptionPane.showMessageDialog(null, "Username and password not correct");

}

}
else if(division=="Engineer"){



if(count==1){

JOptionPane.showMessageDialog(null, "Username and password correct");

Competency_Form_JFrame s = new Competency_Form_JFrame();

s.setVisible(true);

close();

}

else if(count>1){

JOptionPane.showMessageDialog(null, "Duplicate user and password Access denied");
// Level_1_JForm s = new Level_1_JForm();

//s.setVisible(true);

}

else{

JOptionPane.showMessageDialog(null, "Username and password not correct");

}

}


else if(division=="DesignEngineer"){

if(count==1){



JOptionPane.showMessageDialog(null, "Username and password correct");


Competency_Form_JFrame s = new Competency_Form_JFrame();

s.setVisible(true);

close();

}

else if(count>1){

JOptionPane.showMessageDialog(null, "Duplicate user and password Access denied");

//Level_1_JForm s = new Level_1_JForm();

//s.setVisible(true);

}

else{

JOptionPane.showMessageDialog(null, "Username and password not correct");

}

}


}catch(Exception e)

{

JOptionPane.showMessageDialog(null, e);

}
}

Java prog#3. Login Program for java with sqlite [ Mysql ] database PART-1



JPasswordfield
The sql connect jar file can be downloader form this link below




Creating Login Page In Java using NetBeans
code for login using netbeans
Java Netbeans Login
Building a Login Screen for a NetBeans
NetBeans Platform Login Tutorial
create login page contain user id,password,buttons in java using netbeans
NetBeans Platform Login Tutorial
Download Netbeans Login Source Codes


Java prog#3. Login Program for java with sqlite [ Mysql ] database PART-2 



The sql connect jar file can be downloader form this link below

http://code.google.com/p/sqlitebot/downloads/detail?name=sqlitejdbc-v056.jar&can=2&q=

Comments

  1. com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '? AND password = ?' at line 1

    ReplyDelete
  2. the video quality is POOR, it is impossible to see even a single word with clarity.
    fix this problem asap because the video might proove to be quite helpful

    ReplyDelete
  3. no response poor quality ..
    if was done perfectly would help a lot because no such video exists on youtube..
    saving time by not fixing a problem video..

    ReplyDelete
  4. forgot to say that the default int count =0 i i'de change it just to see if the error is there when the count is set to 1

    ReplyDelete

Post a Comment