

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to add the JDBC MySQL driver to an Eclipse project?
To add the JDBC MySQL driver to an Eclipse project, you need to follow the below steps.
The first step is as follows:
Step1: Create a dynamic web project with some name in Eclipse.
Step2: After pressing the Dynamic Web Project, a new window will open. Now give the project name. The screenshot is as follows:
After clicking the Finish button, you will get a project structure. The screenshot is as follows:
Therefore, I have a project name JDBCJarFiles and in WEB-INF, there is a lib folder. You can add JDBC jar files in lib folder. Now, paste the jar files here. The screenshot is as follows:
Now create a Java class to test if it connects to the database or not. First create a class and give class name and click the finish button. The following is the screenshot:
After clicking the finish button, you will get a window like this.
After that write the following code to test the Database connection. Here, we have database name ‘test’, username=’root’ and password is ‘123456’.
The Java code is as follows:
import java.sql.Connection; import java.sql.DriverManager; public class JdbcConnectionDemo { public static void main(String[] args) { String JdbcURL = "jdbc:mysql://localhost:3306/test?useSSL=false"; String Username = "root"; String password = "123456"; Connection con = null; try { System.out.println("Connecting to database..............."+JdbcURL); con=DriverManager.getConnection(JdbcURL, Username, password); System.out.println("Connection is successful!!!!!!"); } catch(Exception e) { e.printStackTrace(); } } }
The screenshot of code is as follows:
The following is the output:
Connecting to database...............jdbc:mysql://localhost:3306/test?useSSL=false Connection is successful!!!!!!
The snapshot of sample output:
- Related Questions & Answers
- How to build an ant file for a Java Eclipse project?
- What is the MySQL JDBC driver connection string?
- How to find package explorer in Java eclipse project?
- How to get the properties of a driver using JDBC?
- Among all 4 JDBC driver types, when to use which driver?
- How to add Cucumber Maven dependencies to the project?
- How to create a Cucumber project template using Maven in Eclipse?
- How to de-register a driver from driver manager’s drivers list using JDBC?
- Is it mandatory to register the driver while working with JDBC?
- How to add Django debug toolbar to your project?
- How to add a new column to an existing table using JDBC API?
- How to add columns to an existing MySQL table?
- How to add current date to an existing MySQL table?
- How to set the initial value of an auto-incremented column in MySQL using JDBC?
- How to escape backslashes in MySQL with JDBC?