Java JDBC Sqlite Connection getConnection(String dbName)

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

Description

get Connection

License

Open Source License

Declaration

public static Connection getConnection(String dbName) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.sql.Connection;
import java.sql.DriverManager;

import java.sql.SQLException;

public class Main {
    private static final String mdbDriver = "org.sqlite.JDBC";
    private static final String mdbUrl = "jdbc:sqlite:";
    private static final String mdbName = "GenericsDaoDB.db3";
    private static final String mdbUser = "";
    private static final String mdbPwd = "";
    private static Connection mConn;

    public static Connection getConnection(String dbName) {
        if (mConn == null) {
            try {
                Class.forName(mdbDriver);
                String connDbName = mdbName;
                if (dbName != null) {
                    connDbName = dbName;
                }//from w  w w  .  j  av a  2s  .  com
                mConn = DriverManager.getConnection(mdbUrl + connDbName, mdbUser, mdbPwd);
            } catch (ClassNotFoundException e) {
                e.printStackTrace();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        } else {
            return mConn;
        }
        return mConn;
    }

    public static Connection getConnection() {
        return getConnection(null);
    }
}

Related

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