Introduction of the Project
Have you ever wanted to make a Bug Tracking System In Java? If yes, Today we are going to create a Java project that will help us to store and report the bugs encountered during software testing. To make the bug tracking system more interactive, we will implement a GUI using Swing and will use an SQL database to store information about bugs, such as their environment, some description, and the type and save status information.
Objectives
The objective of this java project is to create and implement an effective system that will help to monitor the status of bugs in a respective application. All the bugs reported will be stored in the database with a unique ID and assigned a respective status. We have also created columns to store the environment, type, and a brief description of the bug being reported.
Requirements
- Java Compiler IDE
- Swing
Source Code
package com.company; public class Main { public static void main(String[] args) { new Bug(); } } package com.company; import javax.swing.*; import javax.swing.table.DefaultTableModel; import java.awt.* import java.sql.*; import java.util.Vector; public class Bug { private JTextField idData; private JTable table1; private JButton ADDRECORDButton; private JButton UPDATERECORDButton; private JPanel bugPanel; private JTextArea description; private JComboBox product; private JComboBox environment; private JComboBox type; private JComboBox status; JFrame bugF = new JFrame(); public Bug(){ bugF.setContentPane(bugPanel); bugF.pack(); bugF.setLocationRelativeTo(null); bugF.setVisible(true); tableData(); ADDRECORDButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { if(idData.getText().equals("")||description.getText().equals("")){ JOptionPane.showMessageDialog(null,"Please Fill All Fields to add Bug."); }else{ // try { String sql = "insert into bug"+"(Bug_ID,Product,Environment,Type,Description,Status)"+"values (?,?,?,?,?,?)"; Class.forName("com.mysql.cj.jdbc.Driver"); Connection connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/intern","root","root"); PreparedStatement statement = connection.prepareStatement(sql); statement.setInt(1,Integer.parseInt(idData.getText())); statement.setString(2, ""+product.getSelectedItem()); statement.setString(3, ""+environment.getSelectedItem()); statement.setString(4,""+type.getSelectedItem()); statement.setString(5,description.getText()); statement.setString(6,""+status.getSelectedItem()); statement.executeUpdate(); JOptionPane.showMessageDialog(null,"ITEM ADDED SUCCESSFULLY"); idData.setText(""); description.setText(""); }catch (Exception ex){ JOptionPane.showMessageDialog(null,ex.getMessage()); } tableData(); } } }); UPDATERECORDButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { try{ String sql = "UPDATE bug " + "SET Product = '"+ product.getSelectedItem()+"',Environment='"+ environment.getSelectedItem()+ "',Description='"+description.getText()+"',Status='"+status.getSelectedItem()+"'" + " WHERE Bug_ID="+Integer.parseInt(idData.getText()); Class.forName("com.mysql.cj.jdbc.Driver"); Connection connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/intern","root","root"); PreparedStatement statement = connection.prepareStatement(sql); statement.executeUpdate(); JOptionPane.showMessageDialog(null,"Updated successfully"); }catch (Exception e2){ System.out.println(e2); } tableData(); } }); table1.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { DefaultTableModel dm = (DefaultTableModel)table1.getModel(); int selectedRow = table1.getSelectedRow(); idData.setText(dm.getValueAt(selectedRow,0).toString()); description.setText(dm.getValueAt(selectedRow,4).toString()); } }); } public void tableData() { try{ String a= "Select* from bug"; Class.forName("com.mysql.cj.jdbc.Driver"); Connection connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/intern","root","root"); Statement statement = connection.createStatement(); ResultSet rs = statement.executeQuery(a); // table1.setModel(new DefaultTableModel(null, new String[]{"ID", "ITEM NAME", "QUANTITY", "PRICE"})); table1.setModel(buildTableModel(rs)); }catch (Exception ex1){ JOptionPane.showMessageDialog(null,ex1.getMessage()); } } public static DefaultTableModel buildTableModel(ResultSet rs) throws SQLException { ResultSetMetaData metaData = rs.getMetaData(); // names of columns Vector<String> columnNames = new Vector<String>(); int columnCount = metaData.getColumnCount(); for (int column = 1; column <= columnCount; column++) { columnNames.add(metaData.getColumnName(column)); } // data of the table Vector<Vector<Object>> data = new Vector<Vector<Object>>(); while (rs.next()) { Vector<Object> vector = new Vector<Object>(); for (int columnIndex = 1; columnIndex <= columnCount; columnIndex++) { vector.add(rs.getObject(columnIndex)); } data.add(vector); } return new DefaultTableModel(data, columnNames); } }
Explanation of the Code
The code can be divided into two sections. One involves the creation of a GUI, and the other involves the retrieval of information from a SQL database and allowing users to report a bug.
Let’s look at the GUI first:
1. The main screen consists of two buttons: Add record and Update record.
2. We have four text combo boxes, a text field, and a text area that needs information about the bug.
3. It consists of a jtable that displays the information stored in the database.
Now the connection with the SQL database:
1. First, establish a connection to the database using a connection object.
2. Paste a query containing table data into a ResultSet.
3. Finally, send the data to Jtable.
4. Addition & Updating the data require an injection of a query that manipulates the data & finally, using the method tableData() to display data into Jtable.
Output
Main Interface
Conclusion
We have successfully created a Bug Tracking System In Java that helps you report a bug and get bug details using an interactive GUI made using the Swing module. This tracking system is a very efficient and easy way to report a bug, with all details of the bug stored in the database.

Cisco Ramon is an American software engineer who has experience in several popular and commercially successful programming languages and development tools. He has been writing content since last 5 years. He is a Senior Manager at Rude Labs Pvt. Ltd.
0 Comments