コード例 #1
0
ファイル: BAT.java プロジェクト: NotMeIrl/BungeeAdminTools
  public boolean loadSQLiteDriver() {
    final File driverPath =
        new File(getDataFolder() + File.separator + "lib" + File.separator + "sqlite_driver.jar");
    new File(getDataFolder() + File.separator + "lib").mkdir();

    // Download the driver if it doesn't exist
    if (!new File(getDataFolder() + File.separator + "lib" + File.separator + "sqlite_driver.jar")
        .exists()) {
      getLogger().info("The SQLLite driver was not found. It is being downloaded, please wait ...");

      final String driverUrl = "https://www.dropbox.com/s/ls7qoddx9m6t4vh/sqlite_driver.jar?dl=1";
      FileOutputStream fos = null;
      try {
        final ReadableByteChannel rbc = Channels.newChannel(new URL(driverUrl).openStream());
        fos = new FileOutputStream(driverPath);
        fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE);
      } catch (final IOException e) {
        getLogger()
            .severe(
                "An error occured during the downloading of the SQLite driver. Please report this error : ");
        e.printStackTrace();
        return false;
      } finally {
        DataSourceHandler.close(fos);
      }

      getLogger().info("The driver has been successfully downloaded.");
    }

    // Load the driver
    try {
      URLClassLoader systemClassLoader;
      URL u;
      Class<URLClassLoader> sysclass;
      u = driverPath.toURI().toURL();
      systemClassLoader = (URLClassLoader) ClassLoader.getSystemClassLoader();
      sysclass = URLClassLoader.class;
      final Method method = sysclass.getDeclaredMethod("addURL", new Class[] {URL.class});
      method.setAccessible(true);
      method.invoke(systemClassLoader, new Object[] {u});

      Class.forName("org.sqlite.JDBC");
      return true;
    } catch (final Throwable t) {
      getLogger().severe("The sqlite driver cannot be loaded. Please report this error : ");
      t.printStackTrace();
      return false;
    }
  }
コード例 #2
0
ファイル: BAT.java プロジェクト: NotMeIrl/BungeeAdminTools
 public static Connection getConnection() {
   return dsHandler.getConnection();
 }