Login page SQL server 2008 database connection source code

Login page SQL server 2008  database connection source code?

Login Button code:

 private void LoginButtonActionPerformed(java.awt.event.ActionEvent evt) {                                           
              try{
            Class.forName(“com.microsoft.sqlserver.jdbc.SQLServerDriver”);
            String url=”jdbc:sqlserver://localhost:1433;databaseName=testdb;user=sa;password=root”;
            Connection con = DriverManager.getConnection(url);
            String sql = “Select * from test where username=? and password = ?”;
            PreparedStatement pst = con.prepareStatement(sql);
            pst.setString(1, login.getText());
            pst.setString(2,pass.getText());
            ResultSet rs = pst.executeQuery();
            if(rs.next()){
                JOptionPane.showMessageDialog(null, “Username and Password Matched”);
                NewJFrame njf= new NewJFrame();
                njf.setVisible(true);
                setVisible(false);
            
            }
            else{
                JOptionPane.showMessageDialog(null, “Username and password not Correct”);
                login.setText(“”);
                pass.setText(“”);
            }
            con.close();
        }
        catch(Exception e){
            JOptionPane.showMessageDialog(null, e);
        }
    }                                           

Reset Button Code:

        login.setText(“”);
       pass.setText(“”);




Leave a Reply

Your email address will not be published. Required fields are marked *