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

JAVA MySQL Connectivity

The document explains JDBC (Java Database Connectivity), a Java API that enables interaction with relational databases like MySQL. It outlines the steps for Java-MySQL connectivity, including establishing a connection, creating SQL queries, and closing the connection. Additionally, it presents a project to develop a Java-based Student Registration System using JDBC and Swing GUI for user interaction.
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

JAVA MySQL Connectivity

The document explains JDBC (Java Database Connectivity), a Java API that enables interaction with relational databases like MySQL. It outlines the steps for Java-MySQL connectivity, including establishing a connection, creating SQL queries, and closing the connection. Additionally, it presents a project to develop a Java-based Student Registration System using JDBC and Swing GUI for user interaction.
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 10

JAVA

MySQL
Connectivi
ty JAINIKA BISEN
1032222201
T.Y. PC - 41
What is JDBC?
• JDBC (Java Database Connectivity) is a Java API that allows
applications to interact with relational databases like
MySQL, PostgreSQL.
• It provides methods to connect to a database, execute
queries, and process the results.

WHY JDBC?
• Platform-Independent – Works on any system with a JVM
• Supports Multiple Databases – Compatible with MySQL,
PostgreSQL, Oracle, and more.
• Secure & Efficient – Uses PreparedStatement to prevent
SQL injection and optimize performance.
Steps in Java-MySQL Connectivity
1. Establish Connection:
Create a connection to the MySQL database using
DriverManager.
Syntax:
Connection conn = DriverManager.getConnection(url, user,
password)

2. Create Database and Schema in MySQL workbench

3. Create SQL queries and run using PreparedStatement:


Syntax:
PreparedStatement stmt = conn.prepareStatement(query));

4. Close connection:
Problem
Statement
Develop a Java-based Student Registration System that connects to a
MySQL database using JDBC, allowing users to insert student details using
Swing GUI.

The student table should include:


• ID
• Name
• Age
• Enrollment status
Demonstration
1.Create Schema in MySQL: 2. Create a new Maven Project:

Go to File -> New ->Maven Project


Select the option - ‘Create a simple
project’
Demonstration
3. Enter the details:

• Enter Group ID, Artifact ID and


Name.
ex:
GroupID: LAB5
ArtifactID: LAB5
Name: MPJ_Connectivity

• Do not add any parent project


details

• Click finish
Demonstration
4. Add dependencies to pom.xml file

<dependencies>
<dependency>
<groupId>mysql</groupId>

<artifactId>mysql-connector-java</artifactId>
<version>8.0.33</version>
</dependency>
</dependencies>
• The above dependencies add MySQL
Connector, which is essential for Java
applications to communicate with a MySQL
database using JDBC.
Demonstration
5. Write code for connecting java with MySQL
• In src/main/java, create a file and name it with .java extension
Demonstration
6. Run select query to check if data is inserted
7. Develop complete web application

• Swing can be utilized to develop


a GUI-based frontend, providing
an interactive interface for users.

• In a web application,
⚬ Servlets efficiently manage
client requests and responses.

⚬ JSP facilitates the creation of


dynamic web pages by
integrating Java with HTML.
Thank
You

You might also like