0% found this document useful (0 votes)
448 views22 pages

MySQL CRUD Setup in 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)
448 views22 pages

MySQL CRUD Setup in 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
  • Introduction
  • Requirements
  • Prepare Database & Table
  • Setup Netbeans Connector for MySQL
  • CRUD Operations
  • Run the App
  • Conclusion

Simple CRUD with Netbeans

Rizky Tahara Shita


Requirements


MySQL Database Server
– XAMPP
– Manual Install

Windows:
– [Link]
– [Link]

Linux:
– Install dari Repository

Download Connector
– [Link]
– MySQL JDBC Driver
– MySQL Connector
2
Requirements


Download Netbeans
– [Link]

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-
[Link]

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([Link] evt) { // Show to Table


// Connect to Database Server while([Link]()) {
try {
String id = [Link]([Link]("id"));
Connection conn = [Link](
String name = [Link]([Link]("name"));
"jdbc:mysql://localhost/libraryDB",
"user",
String tblData[] = {id, name};
"password"
);
[Link](tblData);
Statement state = [Link](); }

// Get Query } catch(Exception ex) {


PreparedStatement pst = [Link](
[Link](
"select * from categories order by name"
null,
);
"Error : " + ex,
ResultSet rs = [Link]();
"Pesan",

DefaultTableModel tblModel = (DefaultTableModel)[Link](); JOptionPane.ERROR_MESSAGE


);
// Clear the Table Data }
[Link](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