How to connect Java to MySql Database?

0 votes
Hi. Can someone send me the code to connect Java program to MySql Database?
Sep 30, 2019 in Java by slayer
• 29,270 points
151 views

1 answer to this question.

0 votes

Make sure you have the MySQL jdbc connector. And then, try this:

try {

         Class.forName("com.mysql.cj.jdbc.Driver");

         Connection con = DriverManager.getConnection("jdbc:mysql://localhost/mysql?user=root&password=edureka");

  }

  catch (Exception ex) {

         ex.printStackTrace();

  }

And replace the username and password used for the database.

answered Sep 30, 2019 by Shyam

Related Questions In Java

0 votes
1 answer

How to connect Java program to the MySQL database?

You can connect your Java code with ...READ MORE

answered May 11, 2018 in Java by Parth
• 4,640 points
302 views
0 votes
1 answer

How to create database in MySql using Java?

First, you will have to create connection ...READ MORE

answered Sep 30, 2019 in Java by Shri
264 views
+5 votes
3 answers

How to execute a python file with few arguments in java?

You can use Java Runtime.exec() to run python script, ...READ MORE

answered Mar 27, 2018 in Java by DragonLord999
• 8,400 points

edited Nov 6, 2018 by Omkar 17,073 views
0 votes
2 answers

How can I convert a String variable to a primitive int in Java

 Here are two ways illustrating this: Integer x ...READ MORE

answered Aug 20, 2019 in Java by Sirajul
• 50,440 points
341 views
0 votes
2 answers

MySQL "Could not create connection to database serve" error

When I am trying to connect netbeans ...READ MORE

answered Apr 14, 2019 in Database by anonymous

edited Apr 15, 2019 by Kalgi 6,229 views
0 votes
1 answer

Why is not preferable to use mysql_* functions in PHP?

The reasons are as follows: The MySQL extension: Does ...READ MORE

answered Sep 7, 2018 in Database by DataKing99
• 8,130 points
94 views
0 votes
1 answer

Find values in a comma separated string in a MySQL query

You can add commas to the left and ...READ MORE

answered Sep 10, 2018 in Database by Sahiti
• 6,290 points
4,723 views
0 votes
1 answer

How to do a batch insert in MySQL

You can try out the following query: INSERT ...READ MORE

answered Sep 10, 2018 in Database by Sahiti
• 6,290 points
711 views
0 votes
1 answer

How to connect Java to MySql Database?

This will work: try { ...READ MORE

answered Aug 27, 2019 in Java by John
112 views
0 votes
1 answer

How to create database in MySql using Java?

First, you will have to create connection ...READ MORE

answered Aug 27, 2019 in Java by Juni
62 views