Created
July 2, 2021 14:16
-
-
Save pablohdzvizcarra/634e5b3aa2f15a413cac971f33d02996 to your computer and use it in GitHub Desktop.
simple config H2 database to Gradle
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.example.infrastructure; | |
import org.h2.tools.Server; | |
import java.sql.Connection; | |
import java.sql.DriverManager; | |
import java.sql.SQLException; | |
import java.sql.Statement; | |
public class DBLauncher | |
{ | |
public static void main(String[] args) throws SQLException, ClassNotFoundException | |
{ | |
Server.main(); | |
System.out.println("DB Launched"); | |
final String JDBC_DRIVER = "org.h2.Driver"; | |
final String DB_URL = "jdbc:h2:./resources/test-db"; | |
final String USER = ""; | |
final String PASS = ""; | |
Connection connection = null; | |
Statement statement = null; | |
try | |
{ | |
Class.forName(JDBC_DRIVER); | |
connection = DriverManager.getConnection(DB_URL); | |
statement = connection.createStatement(); | |
statement.close(); | |
} catch (Exception exception) | |
{ | |
exception.printStackTrace(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment