Header Ads

NetBeans Project: Part-02 | Employee Management System

Make the Database connection SQLite or MySQL using java.
Right click on the project name in Netbeans, then click New --> Java Class. You can give any name for class name. In my case I will give it as javaconnect.java and Finish.


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

public class javaconnect {
 
    Connection conn = null;
 
    //method
    public static Connection ConnecrDb(){
        try{
            Class.forName("org.sqlite.JDBC");
            /*
                IF YOU ARE USING MYSQL DATABASE
                Class.forName("com.mysql.jdbc.Driver");
            */
            Connection conn = DriverManager.getConnection("jdbc:sqlite:"
                    + "C:\\Users\\abc\\Documents\\NetBeansProjects\\Testing\\test.sqlite");
            JOptionPane.showMessageDialog(null, "Connection Established");
            /*
                IF YOU ARE USING MYSQL DATABASE
                Connection conn = DriverManager.getConnection("jdbc:mysql:"
                    + "//localhost/NAME OF THE DB FILE", "USERNAME", "PASSWORD");
            */
            return conn;
        }
        catch(Exception e){
            JOptionPane.showMessageDialog(null, e);
            return null;
        }
    }
 
}

In next part we will discuss about ‘Login program for the project’ by using Java. If you have any doubts about the part – 02 please don’t hesitate to ask from iTech Digest | Thank you! See you on part - 03

No comments

Thank you very much for your ideas!