0% found this document useful (0 votes)
282 views

Simple CRUD With Netbeans

This document provides instructions for building a simple CRUD application with Netbeans and MySQL. It outlines downloading and installing Netbeans, MySQL, and the MySQL connector. It then walks through creating a database and table, setting up the Netbeans project dependencies, and building out Java classes for a category list and form. Code snippets are provided to connect to the database, populate the list, and save new categories. Running the application allows viewing and managing category data through a basic GUI.

Uploaded by

Hangga Aja
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
282 views

Simple CRUD With Netbeans

This document provides instructions for building a simple CRUD application with Netbeans and MySQL. It outlines downloading and installing Netbeans, MySQL, and the MySQL connector. It then walks through creating a database and table, setting up the Netbeans project dependencies, and building out Java classes for a category list and form. Code snippets are provided to connect to the database, populate the list, and save new categories. Running the application allows viewing and managing category data through a basic GUI.

Uploaded by

Hangga Aja
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 22

Simple CRUD with Netbeans

Rizky Tahara Shita


Requirements


MySQL Database Server
– XAMPP
– Manual Install

Windows:
– https://www.mysql.com/downloads/
– https://dev.mysql.com/downloads/windows/installer/8.0.html

Linux:
– Install dari Repository

Download Connector
– https://dev.mysql.com/downloads/connector/j/
– MySQL JDBC Driver
– MySQL Connector
2
Requirements


Download Netbeans
– https://netbeans.apache.org/download/index.html

Install it!

3
Prepare Database & Table
Prepare Database & Table


Create Database
– create database libraryDB;

Create Table
– use libraryDB;
– create table categories (
id int NOT NULL AUTO_INCREMENT,
name varchar(255) NOT NULL,
PRIMARY KEY (id)
) ENGINE=InnoDB;
5
Prepare Database & Table


Insert Sample Data
– insert into categories (name) values (‘Komputer’);
– insert into categories (name) values (‘Sastra’);

6
Setup Netbeans Connector for MySQL
Create New Project


File > New Project

Java with Maven > Java Application

Entry Project Name

Finish

8
Setup Dependencies


Right Click Dependencies

Add Dependencies

9
Setup Dependencies


Select mysql-connector-java-
8.0.27.jar

Right Click

Select Manual Install Artifact

Browse the MySQL
Connector .jar file

Click Install Locally

10
CRUD: List Form
Category List


Add New JFrame Form

Class Name: CategoryList

Finish

12
Category List

13
Refresh Button

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) { // Show to Table


// Connect to Database Server while(rs.next()) {
try {
String id = String.valueOf(rs.getInt("id"));
Connection conn = DriverManager.getConnection(
String name = String.valueOf(rs.getString("name"));
"jdbc:mysql://localhost/libraryDB",
"user",
String tblData[] = {id, name};
"password"
);
tblModel.addRow(tblData);
Statement state = conn.createStatement(); }

// Get Query } catch(Exception ex) {


PreparedStatement pst = conn.prepareStatement(
JOptionPane.showMessageDialog(
"select * from categories order by name"
null,
);
"Error : " + ex,
ResultSet rs = pst.executeQuery();
"Pesan",

DefaultTableModel tblModel = (DefaultTableModel)jTable1.getModel(); JOptionPane.ERROR_MESSAGE


);
// Clear the Table Data }
tblModel.setRowCount(0); }

14
CRUD: Master Form
Category Form


Add New JFrame Form

Class Name: CategoryForm

Finish

16
Category Form

17
Category List::New Button


Double Click the NEW Button at the Category List

Add the code to Open CategoryForm

18
Category Form::Save Button

19
Run the App


F6 to Run it!

Choose CategoryList as Main
Class

20
The App

21
Thank You
@wukongrita

22

You might also like