Java JDBC HSQL Connection getConnection()

Here you can find the source of getConnection()

Description

get Connection

License

Apache License

Declaration

public static Connection getConnection() 

Method Source Code


//package com.java2s;
//License from project: Apache License 

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

public class Main {
    public static final int PORT = 9002;
    public static final String DB_NAME = "wukonglin";
    public static final String DB_PATH = "./db/";
    public static final String USER_NAME = "sa";
    public static final String PASSWORD = "";
    public static final int SERVER_MODE = 0;
    public static final int STAND_ALONE_MODE = 1;
    public static int mode = SERVER_MODE;

    public static Connection getConnection() {
        Connection conn = null;//  w  w  w.  ja  va  2 s.c o m
        try {
            Class.forName("org.hsqldb.jdbcDriver");
            if (mode == SERVER_MODE) {
                conn = DriverManager.getConnection("jdbc:hsqldb:hsql://localhost:" + PORT + "/" + DB_NAME,
                        USER_NAME, PASSWORD);
            } else if (mode == STAND_ALONE_MODE) {
                conn = DriverManager.getConnection("jdbc:hsqldb:file:" + DB_PATH + DB_NAME, USER_NAME, PASSWORD);
            }
        } catch (ClassNotFoundException ex) {
            ex.printStackTrace();
        } catch (SQLException ex) {
            ex.printStackTrace();
        }
        return conn;
    }
}

Related

  1. createConnection()
  2. createHSQLDBConnection(String hsqldbName)
  3. createSchemasForHSQLDB(String dbName, String[] schemaNames)
  4. createTweetTable()
  5. getDbConnection()
  6. getHSQLConnection()
  7. printSchema()
  8. stopHSQL()