Sei sulla pagina 1di 45

Java MySQL Connectivity

IDE: NetBeans
Jatin Sethi
www.jatinsethi.weebly.com

Getting Ready

Objective
The objective of this document is to give you a brief introduction about:
Java and MySQL connectivity
Accessing (insertion, selection and update) database through an application
How to start application development (2 tier)?

Note: This document is aimed to provide initiation and later you can create large size applications

www.jatin.sethi.weebly.com

Software Requirement (Pre Installed)


JDK
NetBeans
MySQL

www.jatin.sethi.weebly.com

Prerequisite
Basic understanding about SQL like SELECT, INSERT, UPDATE, DELETE etc.
Very Basic knowledge about Java
Meaning of Label, text field and button in Java
If you dont know anything about Java, so practice following programs in Java for building
fundamentals
Print Hello World
Take two numbers from user and print sum
String to Integer conversion
Integer to String conversion

www.jatin.sethi.weebly.com

Database & Table Creation in MySQL

www.jatin.sethi.weebly.com

Putting Some Sample Values in the Table

www.jatin.sethi.weebly.com

Creating a new project

Creating New Project in NetBeans

www.jatin.sethi.weebly.com

Creating New Project in NetBeans

www.jatin.sethi.weebly.com

Creating new jFrame Form

www.jatin.sethi.weebly.com

Creating new jFrame Form

www.jatin.sethi.weebly.com

Designing the Form

www.jatin.sethi.weebly.com

Designing the Form

www.jatin.sethi.weebly.com

Designing the Form

www.jatin.sethi.weebly.com

Designing the Form

www.jatin.sethi.weebly.com

Form Preview

www.jatin.sethi.weebly.com

Calling jFrame form from Main Class

www.jatin.sethi.weebly.com

Adding MySQL Library

www.jatin.sethi.weebly.com

INSERT Query

Database Connectivity (INSERT QUERY)

www.jatin.sethi.weebly.com

Database Connectivity

www.jatin.sethi.weebly.com

Database Connectivity (Error Correction)

www.jatin.sethi.weebly.com

Testing the first connection (RUN)

www.jatin.sethi.weebly.com

Testing Database

www.jatin.sethi.weebly.com

Good Coding

www.jatin.sethi.weebly.com

Testing Again

www.jatin.sethi.weebly.com

SELECT Query

Lets Learn Some More (New Form)

www.jatin.sethi.weebly.com

Designing the Form

www.jatin.sethi.weebly.com

Designing the Form

www.jatin.sethi.weebly.com

Database Connectivity (SELECT QUERY)

www.jatin.sethi.weebly.com

Calling viewdata frame from previous frame

www.jatin.sethi.weebly.com

Testing the second frame (RUN)

www.jatin.sethi.weebly.com

Good Coding

www.jatin.sethi.weebly.com

Testing Again with Wrong Input

www.jatin.sethi.weebly.com

UPDATE Query

Lets Learn Some More (New Form)

www.jatin.sethi.weebly.com

Designing the Form

www.jatin.sethi.weebly.com

Database Connectivity (UPDATE Query)

www.jatin.sethi.weebly.com

Calling updatedata frame from previous frame

www.jatin.sethi.weebly.com

Testing the third Frame (RUN)

www.jatin.sethi.weebly.com

Testing the database

www.jatin.sethi.weebly.com

Self Practice Time


Practice more..
Try difficult queries
Piece of Advice: Since this was first time we were learning hence we made database connection all
the three times while you can make one connection class in java where you can write the database
connectivity code and then you dont need to write it again. Try it by your own

Learn how to close previous window when new window gets opened
Dont get spoon feed, this tutorial is just for your initiation, explore more as much as possible
Note:
The Project (described in this document) is available in ZIP (with all source codes) which could be imported at your machine with the
help of NetBeans.
Also the database file (employee) is also available with this file, you can import at your MySQL server.

www.jatin.sethi.weebly.com

Thanks!
You can contact me at:
http://jatinsethi.weebly.com/contact.html
(recommended for doubts, discussions, suggestions etc.)
jatin.sethi09@gmail.com
(for urgent or really important messages)

www.jatinsethi.weebly.com

Potrebbero piacerti anche