Search in sources :

Example 11 with SQLiteConfig

use of org.sqlite.SQLiteConfig in project hale by halestudio.

the class SpatiaLiteTestSuite method isSpatiaLiteExtensionAvailable.

/**
 * Checks whether the SpatiaLite extension is available on the system, by
 * connecting to the source database and running the query:
 * <p>
 * {@code SELECT load_extension('mod_spatialite')}
 * </p>
 *
 * @return true if the SpatiaLite extension could be loaded, false otherwise
 */
public boolean isSpatiaLiteExtensionAvailable() {
    Connection conn = null;
    try {
        // enabling dynamic extension loading
        // absolutely required by SpatiaLite
        SQLiteConfig config = new SQLiteConfig();
        config.enableLoadExtension(true);
        String dbPath = getSourceTempFilePath();
        if (!new File(dbPath).exists()) {
            createSourceTempFile();
        }
        // create a database connection
        conn = DriverManager.getConnection("jdbc:sqlite:" + dbPath, config.toProperties());
        Statement stmt = conn.createStatement();
        // set timeout to 30 sec.
        stmt.setQueryTimeout(30);
        // loading SpatiaLite
        stmt.execute("SELECT load_extension('mod_spatialite')");
    } catch (Exception e) {
        log.warn("Could not load SpatiaLite extension", e);
        return false;
    } finally {
        try {
            if (conn != null) {
                conn.close();
            }
        } catch (SQLException e) {
        // ignore
        }
    }
    return true;
}
Also used : SQLException(java.sql.SQLException) Statement(java.sql.Statement) Connection(java.sql.Connection) SQLiteConfig(org.sqlite.SQLiteConfig) File(java.io.File) SQLException(java.sql.SQLException) IOException(java.io.IOException)

Example 12 with SQLiteConfig

use of org.sqlite.SQLiteConfig in project selenium_java by sergueik.

the class Controller method initialize.

@FXML
private void initialize() {
    columnSite.setCellValueFactory(new PropertyValueFactory<Website, String>("site"));
    columnSiteLogin.setCellValueFactory(new PropertyValueFactory<Website, String>("siteLogin"));
    columnSitePass.setCellValueFactory(new PropertyValueFactory<Website, String>("sitePass"));
    columnFtp.setCellValueFactory(new PropertyValueFactory<Website, String>("ftp"));
    columnFtpLogin.setCellValueFactory(new PropertyValueFactory<Website, String>("ftpLogin"));
    columnFtpPass.setCellValueFactory(new PropertyValueFactory<Website, String>("ftpPass"));
    columnPort.setCellValueFactory(new PropertyValueFactory<Website, String>("port"));
    columnPerson.setCellValueFactory(new PropertyValueFactory<Website, String>("person"));
    columnPersonEmail.setCellValueFactory(new PropertyValueFactory<Website, String>("personEmail"));
    columnPersonPass.setCellValueFactory(new PropertyValueFactory<Website, String>("personPass"));
    columnPersonPhone.setCellValueFactory(new PropertyValueFactory<Website, String>("personPhone"));
    columnDbName.setCellValueFactory(new PropertyValueFactory<Website, String>("dbName"));
    columnDbUser.setCellValueFactory(new PropertyValueFactory<Website, String>("dbUser"));
    columnDbPass.setCellValueFactory(new PropertyValueFactory<Website, String>("dbPass"));
    columnDbHost.setCellValueFactory(new PropertyValueFactory<Website, String>("dbHost"));
    columnHostingUrl.setCellValueFactory(new PropertyValueFactory<Website, String>("hostingUrl"));
    columnHostingLogin.setCellValueFactory(new PropertyValueFactory<Website, String>("hostingLogin"));
    columnHostingPass.setCellValueFactory(new PropertyValueFactory<Website, String>("hostingPass"));
    columnProviderUrl.setCellValueFactory(new PropertyValueFactory<Website, String>("providerUrl"));
    columnProviderLogin.setCellValueFactory(new PropertyValueFactory<Website, String>("providerLogin"));
    columnProviderPass.setCellValueFactory(new PropertyValueFactory<Website, String>("providerPass"));
    columnOtherUrl.setCellValueFactory(new PropertyValueFactory<Website, String>("otherUrl"));
    columnOtherLogin.setCellValueFactory(new PropertyValueFactory<Website, String>("otherLogin"));
    columnOtherPass.setCellValueFactory(new PropertyValueFactory<Website, String>("otherPass"));
    columnNotes.setCellValueFactory(new PropertyValueFactory<Website, String>("notes"));
    try {
        SQLiteConfig config = new SQLiteConfig();
        c = DB.getInstance().getConnection();
        stat = c.createStatement();
        stat.execute("CREATE TABLE IF NOT EXISTS data(id INTEGER PRIMARY KEY AUTOINCREMENT, site VARCHAR(255), siteLogin VARCHAR(255), sitePass VARCHAR(255), ftp VARCHAR(255), ftpLogin VARCHAR(255), ftpPass VARCHAR(255), port VARCHAR(255), person VARCHAR(255), personEmail VARCHAR(255), personPass VARCHAR(255), personPhone VARCHAR(255), dbName VARCHAR(255), dbUser VARCHAR(255), dbPass VARCHAR(255), dbHost VARCHAR(255), hostingUrl VARCHAR(255), hostingLogin VARCHAR(255), hostingPass VARCHAR(255), providerUrl VARCHAR(255), providerLogin VARCHAR(255), providerPass VARCHAR(255), otherUrl VARCHAR(255), otherLogin VARCHAR(255), otherPass VARCHAR(255), notes VARCHAR(255));");
    } catch (SQLException ex) {
        System.out.println("test");
    }
    fillMainTable();
    tablePassBook.setItems(passbookimpl.getPassbook());
    tablePassBook.getSelectionModel().setCellSelectionEnabled(true);
    tablePassBook.setOnKeyPressed(new TableKeyEventHandler());
    tablePassBook.setOnMouseClicked(new TableMouseEventHandler());
    try {
        fxmlLoader.setLocation(getClass().getResource("/addpassw.fxml"));
        fxmlEdit = fxmlLoader.load();
        addpassw = fxmlLoader.getController();
    } catch (IOException e) {
        e.printStackTrace();
    }
    try {
        fxmlLoader1.setLocation(getClass().getResource("/editpassw.fxml"));
        fxmlEdit1 = fxmlLoader1.load();
        editpassw = fxmlLoader1.getController();
    } catch (IOException e) {
        e.printStackTrace();
    }
}
Also used : SQLiteConfig(org.sqlite.SQLiteConfig) IOException(java.io.IOException) FXML(javafx.fxml.FXML)

Example 13 with SQLiteConfig

use of org.sqlite.SQLiteConfig in project udger-java by udger.

the class UdgerParser method connect.

private void connect() throws SQLException {
    if (connection == null) {
        SQLiteConfig config = new SQLiteConfig();
        config.setReadOnly(true);
        if (inMemoryEnabled) {
            // we cannot use read only for in memory DB since we need to populate this DB from the file.
            connection = DriverManager.getConnection("jdbc:sqlite::memory:");
            File dbfile = new File(parserDbData.dbFileName);
            try (Statement statement = connection.createStatement()) {
                statement.executeUpdate("restore from " + dbfile.getPath());
            } catch (Exception e) {
                LOG.warning("Error re-constructing in memory data base from Db file " + dbfile);
            }
        } else {
            connection = DriverManager.getConnection("jdbc:sqlite:" + parserDbData.dbFileName, config.toProperties());
        }
    }
}
Also used : SQLiteConfig(org.sqlite.SQLiteConfig) File(java.io.File) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException)

Aggregations

SQLiteConfig (org.sqlite.SQLiteConfig)13 SQLException (java.sql.SQLException)5 IOException (java.io.IOException)4 File (java.io.File)3 Connection (java.sql.Connection)3 Test (org.junit.Test)2 UnknownHostException (java.net.UnknownHostException)1 Statement (java.sql.Statement)1 Properties (java.util.Properties)1 FXML (javafx.fxml.FXML)1 IOExceptionWithCause (org.apache.commons.io.IOExceptionWithCause)1 Flyway (org.flywaydb.core.Flyway)1 DriverDataSource (org.flywaydb.core.internal.util.jdbc.DriverDataSource)1 SQLiteDataSource (org.sqlite.SQLiteDataSource)1