Java JDBC Derby Connection existsInSessionTable(String id, boolean verbose)

Here you can find the source of existsInSessionTable(String id, boolean verbose)

Description

exists In Session Table

License

Open Source License

Declaration

public static boolean existsInSessionTable(String id, boolean verbose) 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;

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 boolean existsInSessionTable(String id, boolean verbose) throws Exception {
        Class.forName(DRIVER_CLASS);
        Connection con = null;/*w  ww  .j  ava  2s. c om*/
        try {
            con = DriverManager.getConnection(DEFAULT_CONNECTION_URL);
            PreparedStatement statement = con
                    .prepareStatement("select * from " + TABLE + " where " + ID_COL + " = ?");
            statement.setString(1, id);
            ResultSet result = statement.executeQuery();
            if (verbose) {
                boolean results = false;
                while (result.next()) {
                    results = true;
                }
                return results;
            } else
                return result.next();
        } finally {
            if (con != null)
                con.close();
        }
    }
}

Related

  1. createAndOpen(String databaseName)
  2. createConnection()
  3. createConnection(String userName, String password)
  4. createXATransactionView(Statement s)
  5. deleteTestData()
  6. getConnection()
  7. getConnection()
  8. getDatabaseConnection()
  9. getDefaultDerbyConnection()