Thursday, October 25, 2012

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=

8 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. hi there i have an issue with the code when i login with a username and password and selected the division is says password incorect the Username And password are set it in SqLite Server the division i made it in jcombobox settings here is the code
    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
    try{
    int count=1;

    String sql ="select * from Usersinfo where UsernameID =? and password =? and Division =? ";


    pst=conn.prepareStatement(sql);

    pst.setString(1,jTextField1.getText());
    pst.setString(2,txt_password.getText());
    pst.setString(3, combobox_userselector.getSelectedItem().toString());

    rs=pst.executeQuery();

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



    count=count=1;

    }

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

    if(division=="Admin") {


    if(count==1){

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

    Admin_Platform p= new Admin_Platform();
    //Admin_Platform p new Admin_Platform();
    p.setVisible(true);


    this.dispose();


    }

    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, "Nume Utilizator sau parola incorecte");

    }

    }

    else if(division=="P1") {


    if(count==1){

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

    performer p= new performer();
    //Admin_Platform p new Admin_Platform();
    p.setVisible(true);

    this.dispose();



    }

    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, "Nume Utilizator sau parola incorecte");

    }

    }




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

    }







    }

    ReplyDelete
  5. 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
  6. Really Nice Information,Thank You Very Much For Sharing.
    Web Designing Company

    ReplyDelete