- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- 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 −
Advertisements