1 package org.cacert.gigi.util;
4 import java.io.IOException;
5 import java.nio.file.Files;
6 import java.sql.Connection;
7 import java.sql.DriverManager;
8 import java.sql.SQLException;
9 import java.sql.Statement;
11 public class DatabaseManager {
12 public static String readFile(File f) throws IOException {
13 return new String(Files.readAllBytes(f.toPath()));
15 public static void main(String[] args) throws SQLException,
16 ClassNotFoundException, IOException {
17 if (args.length < 4) {
19 .println("Usage: com.mysql.jdbc.Driver jdbc:mysql://localhost/cacert user password");
24 public static void run(String[] args) throws ClassNotFoundException,
25 SQLException, IOException {
26 Class.forName(args[0]);
27 Connection conn = DriverManager
28 .getConnection(args[1], args[2], args[3]);
29 Statement stmt = conn.createStatement();
30 String sql = readFile(new File("doc/tableStructure.sql"));
31 String[] stmts = sql.split(";");
32 for (String string : stmts) {
33 if (!string.trim().equals("")) {
34 stmt.addBatch(string);