cmd_loginActionPerformed

 String sql = "select * from users where first_name=? and password=?";
//        String sql="select * from Modules 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 are correct");
            Main s=new Main();
            s.setVisible(true);
           
            }else{
               JOptionPane.showMessageDialog(null, "Username and Password are not correct");
            }
        } catch (Exception e) {
        JOptionPane.showMessageDialog(null, e.getMessage());
       
        }


in the main class
 Connection conn = null;
    ResultSet rs = null;
    PreparedStatement pst = null;

    /** Creates new form Login */
    public Login() {
        initComponents();
        conn = javaconnect.ConnecrDB();
    }

Update Table

  private void update_table() {
        try {
            String sql = "select * from Employeeinfo";
            pst = conn.prepareStatement(sql);
            rs = pst.executeQuery();
            tbl_employee.setModel(DbUtils.resultSetToTableModel(rs));
        } catch (SQLException ex) {
            Logger.getLogger(NewJFrame.class.getName()).log(Level.SEVERE, null, ex);
        }
    }


for DbUtils.resultSetToTableModel(rs) need to add jar file of  rs2xml.jar

and then
   Connection conn = null;
    ResultSet rs = null;
    PreparedStatement pst = null;

    /**
     * Creates new form NewJFrame
     */
    public NewJFrame() {
        initComponents();
        conn = javaconnect.ConnecrDB();        update_table();    }

RecordSource


You can use the RecordSource property to specify the source of the data for a form. Read/write String. Syntax
expression.RecordSource
expression   A variable that represents a Form object.
Remarks
The RecordSource property setting can be a table name, a query name, or an SQL statement. For example, you can use the following settings.
Sample setting Description
Employees A table name specifying the Employees table as the source of data.
SELECT Orders!OrderDate FROM Orders; An SQL statement specifying the OrderDate field on the Orders table as the source of data. You can bind a control on the form or report to the OrderDate field in the Orders table by setting the control's ControlSource property to OrderDate.
Bb216003.vs_note(en-us,office.12).gif  Note
Changing the record source of an open form or report causes an automatic requery of the underlying data. If a form's Recordset property is set at runtime, the form's RecordSource property is updated.
After you have created a form or report, you can change its source of data by changing the RecordSource property. The RecordSource property is also useful if you want to create a reusable form or report. For example, you could create a form that incorporates a standard design, then copy the form and change the RecordSource property to display data from a different table, query, or SQL statement.
Limiting the number of records contained in a form's record source can enhance performance, especially when your application is running on a network. For example, you can set a form's RecordSource property to an SQL statement that returns a single record and change the form's record source depending on criteria selected by the user.
Example
The following example sets a form's RecordSource property to the Customers table:
Visual Basic for Applications
Forms!frmCustomers.RecordSource = "Customers"
The next example changes a form's record source to a single record in the Customers table, depending on the company name selected in the cmboCompanyName combo box control. The combo box is filled by an SQL statement that returns the customer ID (in the bound column) and the company name. The CustomerID has a Text data type.
Visual Basic for Applications
Sub cmboCompanyName_AfterUpdate()
    Dim strNewRecord As String
    strNewRecord = "SELECT * FROM Customers " _
        & " WHERE CustomerID = '" _
        & Me!cmboCompanyName.Value & "'"
    Me.RecordSource = strNewRecord
End Sub

RecordsetClone


You can use the RecordsetClone property to refer to a form's Recordset object specified by the form's RecordSource property. Read-only. Syntax
expression.RecordsetClone
expression   A variable that represents a Form object.
Remarks
The RecordsetClone property setting is a copy of the underlying query or table specified by the form's RecordSource property. If a form is based on a query, for example, referring to the RecordsetClone property is the equivalent of cloning a Recordset object by using the same query. If you then apply a filter to the form, the Recordset object reflects the filtering.
This property is available only by using Visual Basic and is read-only in all views.
You use the RecordsetClone property to navigate or operate on a form's records independent of the form itself. For example, you can use the RecordsetClone property when you want to use a method, such as the DAO Find methods, that can't be used with forms.
When a new Recordset object is opened, its first record is the current record. If you one of the Find method or one of the Move methods to make any other record in the Recordset object current, you must synchronize the current record in the Recordset object with the form's current record by assigning the value of the DAO Bookmark property to the form's Bookmark property.
Example
The following example uses the RecordsetClone property to create a new clone of the Recordset object from the Orders form and then prints the names of the fields in the Immediate window.
Visual Basic for Applications
Sub Print_Field_Names()
    Dim rst As Recordset, intI As Integer
    Dim fld As Field

    Set rst = Me.RecordsetClone
    For Each fld in rst.Fields
        ' Print field names.
        Debug.Print fld.Name
    Next
End Sub
The next example uses the RecordsetClone property and the Recordset object to synchronize a recordset's record with the form's current record. When a company name is selected from a combo box, the FindFirst method is used to locate the record for that company and the Recordset object's DAO Bookmark property is assigned to the form's Bookmark property, causing the form to display the found record.
Visual Basic for Applications
Sub SupplierID_AfterUpdate()
    Dim rst As Recordset
    Dim strSearchName As String

    Set rst = Me.RecordsetClone
    strSearchName = Str(Me!SupplierID)
    rst.FindFirst "SupplierID = " & strSearchName
        If rst.NoMatch Then
            MsgBox "Record not found"
        Else
            Me.Bookmark = rst.Bookmark
        End If
    rst.Close
End Sub
You can use the RecordCount property to count the number of records in a Recordset object. The following example shows how you can combine the RecordCount property and the RecordsetClone property to count the records in a form:
Visual Basic for Applications
Forms!Orders.RecordsetClone.MoveLast
MsgBox "My form contains " _
    & Forms!Orders.RecordsetClone.RecordCount _
    & " records.", vbInformation, "Record Count"
Reference:
import java.sql.*;
import javax.swing.*;
import java.awt.*;



Befor you begion initialize your form:
   
   Connection conn = null;
    ResultSet rs = null;
    PreparedStatement pst = null;

in your constructor of your form. In this case login
  public Login() {
        initComponents();
        conn = javaconnect.ConnecrDB();
    }
when button clicked check for login:

private void cmd_loginActionPerformed(java.awt.event.ActionEvent evt) {                                         
        String sql = "select * from users where first_name=? and password=?";
//        String sql="select * from Modules 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 are correct");
            }
        } catch (Exception e) {
        JOptionPane.showMessageDialog(null, e.getMessage());
       
        }
    }     

javaconnect.java

javaconnect.java


import java.sql.*;
import javax.swing.JOptionPane;

public class javaconnect {
 Connection conn= null;
 public static Connection ConnecrDB(){
     try {
         Class.forName("org.sqlite.JDBC");
         Connection conn =DriverManager.getConnection("jdbc:sqlite:\\C:\\GD\\Google Drive\\Java\\Squilt\\Project123.sqlite");
        JOptionPane.showMessageDialog(null, "Connection Established"+conn);
         return conn;
     } catch (Exception e) {
         //JOptionPane.showMessageDialog(null, e);
         JOptionPane.showMessageDialog(null, "Connection stablished");
           JOptionPane.showMessageDialog(null, e.getMessage());
         return null;
     }
    
 }
}