JAVA MySQL Connectivity
JAVA MySQL Connectivity
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)
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.
• 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
• In a web application,
⚬ Servlets efficiently manage
client requests and responses.