Java JDBC Sqlite Connection getConnection(String dbFile)

Here you can find the source of getConnection(String dbFile)

Description

get Connection

License

Open Source License

Declaration

public static Connection getConnection(String dbFile) throws SQLException, URISyntaxException 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * SQLPatcher - <a//w  ww .java 2 s . c  o m
 * href="https://github.com/kbss/SQLPatcher">https://github.com/kbss
 * /SQLPatcher</a><br>
 * 
 * Copyright (C) 2013 Serhii Krivtsov<br>
 * 
 * SQLPatcher is free software; you can redistribute it and/or modify it under
 * the terms of the GNU General Public License as published by the Free Software
 * Foundation; either version 2 of the License, or (at your option) any later
 * version.<br>
 * <br>
 * SQLPatcher is distributed in the hope that it will be useful, but WITHOUT ANY
 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
 * A PARTICULAR PURPOSE. See the GNU General Public License for more details.
 * You should have received a copy of the GNU General Public License along with
 * this program. If not, see <http://www.gnu.org/licenses/>. <br>
 * 
 * @author Serhii Krivtsov
 ******************************************************************************/

import java.io.File;

import java.net.URISyntaxException;
import java.sql.Connection;
import java.sql.DriverManager;

import java.sql.SQLException;

import java.util.Properties;

public class Main {
    public static Connection getConnection(String dbFile) throws SQLException, URISyntaxException {
        try {
            Class.forName("org.sqlite.JDBC");
        } catch (ClassNotFoundException e) {
            throw new RuntimeException(e);
        }
        Properties connectionProps = new Properties();
        connectionProps.setProperty("flags", "READONLY");
        Connection connection = DriverManager.getConnection("jdbc:sqlite:" + new File(dbFile).toURI().getPath(),
                connectionProps);
        return connection;
    }
}

Related

  1. checkConnection()
  2. createTable(final String databaseName, final String statement)
  3. createTable(String database, String sqlScript)
  4. getConnection()
  5. getConnection(final String databaseName)
  6. getConnection(String dbFilePath)
  7. getConnection(String dbName)
  8. getNewConnection(File dbFile)
  9. getSenatorProp(String topicId)