

- 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 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 Questions & Answers
- Connect to MySQL database from command line
- How to allow a MySQL user account to connect from any host?
- How does spring boot connect localhost MySQL
- How to connect to an SAP module?
- How to connect to SSH using PowerShell?
- Best way to connect to SAP system from JAVA
- How to connect Database in Python?
- How to force MySQL to connect by TCP instead of a Unix socket?
- How to connect to Chromium Headless using Selenium?
- Using SAP JCO to connect SAP server to JAVA application
- How to connect Azure Account using PowerShell?
- How to connect to SAP database using ODBC driver
- How to Connect a DB to pgAdmin in PostgreSQL ?
- How to connect MariaDB with Third Party database?
- How to connect to Derby database using a JDBC program?
Advertisements