Create a database using JDBC

JDBC is not intended to manage databases. It’s used to connect to them. Creating a database is not standard, every DMBS has another way of doing it. If you’re willing to give up portability accross databases, there are ways. For example, in mysql, you can connect to an existing database and invoke executeUpdate to create a new database.

Main.java:

import java.util.*;
import java.sql.*;
  
public class Main {
   public static void main(String []args) throws Exception {
      try {
         Class.forName("org.gjt.mm.mysql.Driver").newInstance();
         Connection conn = DriverManager.getConnection("jdbc:mysql://192.168.0.1/esus", 
                                                       "joris",
                                                       "mypass");
 
         Statement stmt = conn.createStatement();
         stmt.executeUpdate("create database testdb");
      }
      catch(Exception e) {
         e.printStackTrace();
      }
   } 
}