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
76 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,090 points
126 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,190 points
246 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,630 points
378 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,890 points
144 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,060 points
100 views
0 votes
3 answers

MySQL "Could not create connection to database serve" error

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

answered 13 hours ago in Database by anonymous
9,132 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
158 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
598 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
661 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
• 54,020 points
580 views