- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- 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 connect Java to MySQL?
To connect Java to MySQL, the Java code is as follows −
import java.sql.Connection; import java.sql.DriverManager; public class LostConnectionURLDemo { public static void main(String[] args){ String JDBCURL="jdbc:mysql://localhost:3306/web?autoReconnect=true"; Connection con=null; try{ con = DriverManager.getConnection(JDBCURL,"root","123456"); System.out.println("connection is established"); } catch(Exception e){ e.printStackTrace(); } } }
This will produce the following output −
- Related Articles
- How to connect hibernate with MySQL Database?
- Connect to MySQL database from command line
- How to allow a MySQL user account to connect from any host?
- How to force MySQL to connect by TCP instead of a Unix socket?
- Best way to connect to SAP system from JAVA
- How does spring boot connect localhost MySQL
- How to connect to an SAP module?
- How to connect to SSH using PowerShell?
- Using SAP JCO to connect SAP server to JAVA application
- How to connect Database in Python?
- How to connect to Chromium Headless using Selenium?
- How to connect Azure Account using PowerShell?
- How to connect your YouTube mobile App to TV?
- How to connect to Derby database using a JDBC program?
- How to connect to HSQLDB database using a JDBC program?

Advertisements