Java SQL Time Create getWaitTimeout(Connection con)

Here you can find the source of getWaitTimeout(Connection con)

Description

get Wait Timeout

License

Open Source License

Declaration

private static long getWaitTimeout(Connection con) 

Method Source Code

//package com.java2s;
/*/*from  ww w.java  2  s  .  co m*/
 * This file is part of RuneSource.
 *
 * RuneSource is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * RuneSource is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with RuneSource.  If not, see <http://www.gnu.org/licenses/>.
 */

import java.sql.Connection;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class Main {
    private static long getWaitTimeout(Connection con) {
        Statement stmt = null;
        ResultSet rs = null;
        try {
            stmt = con.createStatement();
            rs = stmt.executeQuery("SHOW VARIABLES LIKE 'wait_timeout'");
            if (rs.next()) {
                return Math.max(1000, rs.getInt(2) * 1000 - 1000);
            } else {
                return -1;
            }
        } catch (SQLException ex) {
            return -1;
        } finally {
            close(rs);
            close(stmt);
        }
    }

    public static void close(ResultSet rs) {
        try {
            rs.close();
        } catch (Exception e) {
        }
    }

    public static void close(Statement stmt) {
        try {
            stmt.close();
        } catch (Exception e) {
        }
    }

    public static void close(Connection conn) {
        try {
            conn.close();
        } catch (Exception e) {
        }
    }
}

Related

  1. getTimeZone(String id)
  2. getTimeZone(String timezone, String time, DateFormat format)
  3. getTodayAndTime()
  4. getTomorrowOrderTime()
  5. getUserToServerDateTime(TimeZone timeZone, int dateFormat, int timeFormat, String date, Locale locale)
  6. getYear(String dateTime)
  7. getYear(String dateTime)
  8. substract(Time thisDeparture, Time firstDeparture)
  9. SumTime(Time t1, Time t2)