How to create database in MySql using Java

0 votes
I am using MySql to store data of a Java application. I want to create a database. How can I do it using Java code?
Aug 27, 2019 in Java by Karan
760 views

1 answer to this question.

0 votes

First, you will have to create connection to the MySql server with the right username and password. And then prepare a Sql query and execute it. Code:

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

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

  Statement stmt = connection.createStatement();

      String sql = "CREATE DATABASE EMPLOYEE";

      stmt.executeUpdate(sql);
answered Aug 27, 2019 by Juni

Related Questions In Java

0 votes
2 answers

How to create a 2-D array in java?

int[][] multi = new int[5][]; multi[0] = new ...READ MORE

answered Jul 16, 2018 in Java by Daisy
• 8,140 points
1,544 views
0 votes
2 answers

How can I create File and write data in it using Java?

import java.io.BufferedWriter; import java.io.IOException; import java.nio.file.Files; import java.nio.file.Paths; public class WriteFiles{ ...READ MORE

answered Jul 26, 2018 in Java by samarth295
• 2,220 points
2,923 views
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
1,913 views
0 votes
1 answer

How to encode data using Base64 in Java?

import org.apache.commons.codec.binary.Base64; We can not use sun.* packages ...READ MORE

answered May 30, 2018 in Java by Sushmita
• 6,920 points
1,062 views
0 votes
1 answer

Accessing connection from different class in Java / MySQL?

You should just instantiate DoComms with every ...READ MORE

answered Nov 14, 2018 in Database by nirvana
• 3,130 points
1,946 views
0 votes
3 answers

MySQL "Could not create connection to database serve" error

Pls check that you have MySQL server ...READ MORE

answered Jul 3, 2020 in Database by anonymous
29,899 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
1,138 views
0 votes
1 answer

Java and MySql: Check if database exists

You can get the list of databases ...READ MORE

answered Aug 27, 2019 in Java by Kunal
4,509 views
+1 vote
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
3,293 views
0 votes
2 answers

How to convert an int array to string using tostring method in java?

Use java.util.Arrays: String res = Arrays.toString(array); System. ...READ MORE

answered Aug 16, 2019 in Java by Sirajul
• 59,230 points
2,398 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP