Java JDBC Derby Connection getSessionIds()

Here you can find the source of getSessionIds()

Description

get Session Ids

License

Open Source License

Declaration

public static Set<String> getSessionIds() throws Exception 

Method Source Code


//package com.java2s;
//  are made available under the terms of the Eclipse Public License v1.0

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

import java.util.HashSet;
import java.util.Set;

public class Main {
    public static final String DRIVER_CLASS = "org.apache.derby.jdbc.EmbeddedDriver";
    public static final String DEFAULT_CONNECTION_URL = "jdbc:derby:memory:sessions;create=true";
    public static final String TABLE = "mysessions";
    public static final String ID_COL = "mysessionid";

    public static Set<String> getSessionIds() throws Exception {
        HashSet<String> ids = new HashSet<String>();
        Class.forName(DRIVER_CLASS);
        Connection con = null;//from  www  . j  av  a 2s  . co  m
        try {
            con = DriverManager.getConnection(DEFAULT_CONNECTION_URL);
            PreparedStatement statement = con.prepareStatement("select " + ID_COL + " from " + TABLE);
            ResultSet result = statement.executeQuery();
            while (result.next()) {
                ids.add(result.getString(1));
            }
            return ids;
        } finally {
            if (con != null)
                con.close();
        }
    }
}

Related

  1. getDerbyDatabaseProperty(Statement derbyStatementForQuerying, String propertyKey)
  2. getDerbyUnitConnection()
  3. getDriver(String className)
  4. getLocalConnection()
  5. getRowsFromDatabase(Connection con, int numberOfRows, boolean reuseConnection, String driver, String dsn, String user, String password, String tableName, String whereString, String orderByString, String groupByString)
  6. getSize2()
  7. getTables(File database)
  8. printStats(String statstring)
  9. removeUnitDB()