当前位置: 首页>>代码示例>>Java>>正文


Java SQLiteConfig类代码示例

本文整理汇总了Java中org.sqlite.SQLiteConfig的典型用法代码示例。如果您正苦于以下问题:Java SQLiteConfig类的具体用法?Java SQLiteConfig怎么用?Java SQLiteConfig使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


SQLiteConfig类属于org.sqlite包,在下文中一共展示了SQLiteConfig类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: connect

import org.sqlite.SQLiteConfig; //导入依赖的package包/类
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());
        }
    }
}
 
开发者ID:udger,项目名称:udger-java,代码行数:19,代码来源:UdgerParser.java

示例2: create

import org.sqlite.SQLiteConfig; //导入依赖的package包/类
public static Connection create(String url) throws Exception {
	Class.forName("org.sqlite.JDBC");
	SQLiteConfig config = new SQLiteConfig();
	config.setJournalMode(SQLiteConfig.JournalMode.WAL);
	config.setBusyTimeout("5000");
	config.setTransactionMode(SQLiteConfig.TransactionMode.EXCLUSIVE);

	Connection conection = DriverManager.getConnection("jdbc:sqlite:", config.toProperties());

	Statement statement = conection.createStatement();
	statement.executeUpdate("BEGIN IMMEDIATE;");
	StatementUtils.runSqlScript(statement, "/com/exscudo/peer/store/sqlite/DBv1.sql");
	StatementUtils.runSqlScript(statement, "/com/exscudo/peer/store/sqlite/DBv2.sql");
	StatementUtils.runSqlScript(statement, "/com/exscudo/peer/store/sqlite/DBv2_clean.sql");
	StatementUtils.runSqlScript(statement, "/com/exscudo/peer/store/sqlite/DBv3.sql");
	StatementUtils.runSqlScript(statement, url);
	statement.executeUpdate("COMMIT;");

	return conection;
}
 
开发者ID:EonTechnology,项目名称:server,代码行数:21,代码来源:ConnectionUtils.java

示例3: CreateConnection

import org.sqlite.SQLiteConfig; //导入依赖的package包/类
private static Connection CreateConnection(String dbname, int cache_size, boolean safe_write, boolean journal, boolean autocommit) {
    Connection connection = null;

    try {
        SQLiteConfig config = new SQLiteConfig();
        config.setCacheSize(cache_size);
        config.setSynchronous(safe_write ? SQLiteConfig.SynchronousMode.FULL : SQLiteConfig.SynchronousMode.NORMAL);
        config.setTempStore(SQLiteConfig.TempStore.MEMORY);
        config.setJournalMode(journal ? SQLiteConfig.JournalMode.TRUNCATE : SQLiteConfig.JournalMode.OFF);
        connection = DriverManager.getConnection("jdbc:sqlite:" + dbname.replaceAll("\\\\", "/"), config.toProperties());
        connection.setAutoCommit(autocommit);
    } catch (SQLException ex) {
        com.gmt2001.Console.err.printStackTrace(ex);
    }

    return connection;
}
 
开发者ID:GloriousEggroll,项目名称:quorrabot,代码行数:18,代码来源:SqliteStore.java

示例4: ResultsDatabase

import org.sqlite.SQLiteConfig; //导入依赖的package包/类
public ResultsDatabase(String resultsDatabaseLocation) {

        if (!new File(resultsDatabaseLocation).exists()) {
            throw new RuntimeException("Results database file \"" + resultsDatabaseLocation + "\" does not exist");
        }

        try {
            Class.forName("org.sqlite.JDBC");

            // enforce the foreign keys that are specified in the
            // relational schema; this could be turned off if you are
            // debugging and the data generation subsystem is not yet
            // generating data to satisfy the constraints.
            SQLiteConfig config = new SQLiteConfig();
            config.enforceForeignKeys(true);

            // create the connection to the database,
            // using the properties for the SQLiteConfig
            // object to handle referential integrity's on/off switch
            connection = DriverManager.getConnection("jdbc:sqlite:" + resultsDatabaseLocation, config.toProperties());

        } catch (ClassNotFoundException | SQLException e) {
            throw new RuntimeException(e);
        }
    }
 
开发者ID:schemaanalyst,项目名称:schemaanalyst,代码行数:26,代码来源:ResultsDatabase.java

示例5: Database

import org.sqlite.SQLiteConfig; //导入依赖的package包/类
public Database() throws SQLException, ClassNotFoundException, NullPointerException, SettingsException {
    
    File f = new File(Settings.getValue("db_name"));
    if(!f.exists() || f.isDirectory()) throw new SettingsException("Brak pliku lokalnej bazy danych "
            + f.getPath());        
    f = new File(Settings.getValue("db_spatial_name"));
    if(!f.exists() || f.isDirectory()) throw new SettingsException("Brak pliku lokalnej bazy danych "
            + "przestrzennych: " + f.getPath());
   
     
    Class.forName("org.sqlite.JDBC");         
    SQLiteConfig config = new SQLiteConfig();
    config.enableLoadExtension(true);
    connection = DriverManager.getConnection("jdbc:sqlite:" 
    		+ Settings.getValue("db_name"), config.toProperties());
   
    statement = connection.createStatement();
    statement.setQueryTimeout(30);
    
    // załadowanie Spatialite i dołączenie b.d. przestrzennych
    statement.execute("SELECT load_extension('mod_spatialite')" );                  
    statement.execute("ATTACH DATABASE '" + Settings.getValue("db_spatial_name") + "' AS spatial;");
    
    
}
 
开发者ID:makaw,项目名称:somado,代码行数:26,代码来源:Database.java

示例6: getConnection

import org.sqlite.SQLiteConfig; //导入依赖的package包/类
/**
 * open and return database connections
 */
private Connection getConnection() 
{
	Connection connection;
	SQLiteConfig sc = new SQLiteConfig();
	sc.setEncoding(SQLiteConfig.Encoding.UTF_8);
	try 
	{
		connection = DriverManager.getConnection(connPrefix
				+ config.databaseFilename, sc.toProperties());
		stdOut.println(moduleName + ": Opened database file: " + config.databaseFilename);
	} 
	catch (SQLException e) 
	{
		stdErr.println(e.getMessage());
		return null;
	}
	return connection;
}
 
开发者ID:burp-hash,项目名称:burp-hash,代码行数:22,代码来源:Database.java

示例7: CreateConnection

import org.sqlite.SQLiteConfig; //导入依赖的package包/类
private static Connection CreateConnection(String dbname, int cache_size, boolean safe_write)
{
    Connection connection = null;

    try
    {
        SQLiteConfig config = new SQLiteConfig();
        config.setCacheSize(cache_size);
        config.setSynchronous(safe_write ? SQLiteConfig.SynchronousMode.FULL : SQLiteConfig.SynchronousMode.NORMAL);
        connection = DriverManager.getConnection("jdbc:sqlite:" + dbname.replaceAll("\\\\", "/"), config.toProperties());
        connection.setAutoCommit(true);
    } catch (SQLException ex)
    {
        com.gmt2001.Console.err.printStackTrace(ex);
    }

    return connection;
}
 
开发者ID:gmt2001,项目名称:PhantomBot,代码行数:19,代码来源:SqliteStore.java

示例8: setSyncAndJournaling

import org.sqlite.SQLiteConfig; //导入依赖的package包/类
public static void setSyncAndJournaling(final Connection connection, final SQLiteConfig.SynchronousMode pragmaSynchronous, final SQLiteConfig.JournalMode pragmaJournalMode){
    Statement statement = null;
    try {
        final boolean autoCommit = DBUtils.setAutoCommit(connection, true);
        statement = connection.createStatement();
        statement.execute("PRAGMA synchronous = " + pragmaSynchronous.getValue());

        // This little transaction will also cause a wanted fsync on the OS to flush the data still in the OS cache to disc.
        statement.execute("PRAGMA journal_mode = " + pragmaJournalMode.getValue());

        DBUtils.setAutoCommit(connection, autoCommit);
    }catch (SQLException e){
        throw new IllegalStateException("Unable to set the 'synchronous' and 'journal_mode' pragmas", e);
    }finally{
        DBUtils.closeQuietly(statement);
    }
}
 
开发者ID:npgall,项目名称:cqengine,代码行数:18,代码来源:DBQueries.java

示例9: getPragmaSynchronousOrNull

import org.sqlite.SQLiteConfig; //导入依赖的package包/类
public static SQLiteConfig.SynchronousMode getPragmaSynchronousOrNull(final Connection connection){
    Statement statement = null;
    try {
        statement = connection.createStatement();
        ResultSet resultSet = statement.executeQuery("PRAGMA synchronous;");
        if (resultSet.next()){
            final int syncPragmaId = resultSet.getInt(1);
            if (!resultSet.wasNull()) {
                switch (syncPragmaId){
                    case 0: return SQLiteConfig.SynchronousMode.OFF;
                    case 1: return SQLiteConfig.SynchronousMode.NORMAL;
                    case 2: return SQLiteConfig.SynchronousMode.FULL;
                    default: return null;
                }
            }
        }
        return null;
    }catch (Exception e){
        return null;
    }finally{
        DBUtils.closeQuietly(statement);
    }
}
 
开发者ID:npgall,项目名称:cqengine,代码行数:24,代码来源:DBQueries.java

示例10: getPragmaJournalModeOrNull

import org.sqlite.SQLiteConfig; //导入依赖的package包/类
public static SQLiteConfig.JournalMode getPragmaJournalModeOrNull(final Connection connection){
    Statement statement = null;
    try {
        statement = connection.createStatement();
        ResultSet resultSet = statement.executeQuery("PRAGMA journal_mode;");
        if (resultSet.next()){
            final String journalMode = resultSet.getString(1);
            return journalMode != null ? SQLiteConfig.JournalMode.valueOf(journalMode.toUpperCase()) : null;
        }
        return null;
    }catch (Exception e){
        return null;
    }finally{
        DBUtils.closeQuietly(statement);
    }
}
 
开发者ID:npgall,项目名称:cqengine,代码行数:17,代码来源:DBQueries.java

示例11: connect

import org.sqlite.SQLiteConfig; //导入依赖的package包/类
public void connect() {
	try {
		Class.forName("org.sqlite.JDBC");
		connection = DriverManager.getConnection("jdbc:sqlite:" + DBPath);

		statement = connection.createStatement();
		System.out.println("Connexion � " + DBPath + " avec succ�s");

		SQLiteConfig config = new SQLiteConfig();  
		config.enforceForeignKeys(true);  
		connection = DriverManager.getConnection("jdbc:sqlite:" + DBPath,config.toProperties());

	} catch (ClassNotFoundException notFoundException) {
		notFoundException.printStackTrace();
		System.out.println("Erreur de connexion");
	} catch (java.sql.SQLException sqlException) {
		sqlException.printStackTrace();
		System.out.println("Erreur de connexion");
	}
}
 
开发者ID:Kaysoro,项目名称:carnet-chasse-otomai,代码行数:21,代码来源:Connexion.java

示例12: getConnection

import org.sqlite.SQLiteConfig; //导入依赖的package包/类
/**
 * @return Database connection.
 * @throws ClassNotFoundException Exception while trying to use JDBC driver
 * @throws SQLException           Exception while trying to connect to
 *                                database
 * @throws ExceptionHandler       Exception while accessing config directory
 */
public static Connection getConnection()
        throws ClassNotFoundException, SQLException, ExceptionHandler {
    if (DB_FILE.getParentFile().exists()
            || DB_FILE.getParentFile().mkdirs()) {
        if (!DB_FILE.exists()) {
            try {
                Config.setValue(Config.PROP_SCHEMA_VERSION,
                        String.valueOf(SCHEMA_VERSION));
            } catch (IOException e) {
                ExceptionDialog.show(e);
                LOGGER.error(e);
                e.printStackTrace();
            }
        }
        Class.forName(DRIVER);
        SQLiteConfig config = new SQLiteConfig();
        config.enforceForeignKeys(true);
        return DriverManager.getConnection(DB_URL, config.toProperties());
    } else {
        throw new ExceptionHandler(Error.DB_CONNECTION);
    }

}
 
开发者ID:Alkisum,项目名称:YTSubscriber,代码行数:31,代码来源:Database.java

示例13: CoreConnection

import org.sqlite.SQLiteConfig; //导入依赖的package包/类
protected CoreConnection(String url, String fileName, Properties prop) throws SQLException
{
    this.url = url;
    this.fileName = fileName;

    SQLiteConfig config = new SQLiteConfig(prop);
    this.dateClass = config.dateClass;
    this.dateMultiplier = config.dateMultiplier;
    this.dateFormat = new SimpleDateFormat(config.dateStringFormat);
    this.datePrecision = config.datePrecision;
    this.transactionMode = config.getTransactionMode();
    this.openModeFlags = config.getOpenModeFlags();

    open(openModeFlags, config.busyTimeout);

    if (fileName.startsWith("file:") && !fileName.contains("cache="))
    {   // URI cache overrides flags
        db.shared_cache(config.isEnabledSharedCache());
    }
    db.enable_load_extension(config.isEnabledLoadExtension());

    // set pragmas
    config.apply((Connection)this);
}
 
开发者ID:decamp,项目名称:sqlcipher-jdbc,代码行数:25,代码来源:CoreConnection.java

示例14: start

import org.sqlite.SQLiteConfig; //导入依赖的package包/类
@Override
public void start() throws SQLException, ClassNotFoundException {
	File file = new File(metaData.getDataPath()+File.separator+metaData.getDatabaseName());
	if(!file.exists()){
		throw new SQLException("File not found");
	}
	
	SQLiteConfig conf = new SQLiteConfig();
	conf.setSynchronous(SynchronousMode.OFF);

	String url = Utils.replaceParams(dbConfig.getDbURL(), metaData);

	url = url.replace("__FILE_SEPARATOR__", File.separator);
	String driver = dbConfig.getDriver();
	Class.forName(driver);
	Properties prop = Utils.replaceParams(dbConfig.getConfigProperty(), metaData);
	SQLiteConfig config = new SQLiteConfig(prop);
	config.setSynchronous(SynchronousMode.OFF);
	conn = DriverManager.getConnection(url, config.toProperties());
	// conn.setAutoCommit(false);
}
 
开发者ID:heartsome,项目名称:translationstudio8,代码行数:22,代码来源:TMDatabaseImpl.java

示例15: CoreConnection

import org.sqlite.SQLiteConfig; //导入依赖的package包/类
protected CoreConnection(String url, String fileName, Properties prop) throws SQLException
{
    this.url = url;
    this.fileName = extractPragmasFromFilename(fileName, prop);

    SQLiteConfig config = new SQLiteConfig(prop);
    this.dateClass = config.dateClass;
    this.dateMultiplier = config.dateMultiplier;
    this.dateFormat = FastDateFormat.getInstance(config.dateStringFormat);
    this.dateStringFormat = config.dateStringFormat;
    this.datePrecision = config.datePrecision;
    this.transactionMode = config.getTransactionMode();
    this.openModeFlags = config.getOpenModeFlags();

    open(openModeFlags, config.busyTimeout);

    if (fileName.startsWith("file:") && !fileName.contains("cache="))
    {   // URI cache overrides flags
        db.shared_cache(config.isEnabledSharedCache());
    }
    db.enable_load_extension(config.isEnabledLoadExtension());

    // set pragmas
    config.apply((Connection)this);

}
 
开发者ID:xerial,项目名称:sqlite-jdbc,代码行数:27,代码来源:CoreConnection.java


注:本文中的org.sqlite.SQLiteConfig类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。