Java JDBC MySQL Connection searchServerPropertySplitMinutes()

Here you can find the source of searchServerPropertySplitMinutes()

Description

search Server Property Split Minutes

License

Open Source License

Declaration

public static String searchServerPropertySplitMinutes() 

Method Source Code


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

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

public class Main {
    private static String DB_URL = "jdbc:mysql://localhost:3306/bettaserver";
    private static String DB_USERNAME = "root";
    private static String DB_PASSWORD = "123456";

    public static String searchServerPropertySplitMinutes() {
        String result = "5";
        Connection con = null;/*  w w  w .  j a v  a 2 s . com*/
        PreparedStatement pstmt = null;
        ResultSet rs = null;
        String sql = "select valor from parametros where chave = ?";

        try {
            con = getConnection();
            pstmt = con.prepareStatement(sql);
            {
                pstmt.setString(1, "MOVIE_TIME_SLICE");
            }
            rs = pstmt.executeQuery();

            if (rs.next()) {
                result = rs.getString("valor");
            }
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            close(con, pstmt, rs);
        }

        return result;
    }

    public static Connection getConnection() throws SQLException {
        return DriverManager.getConnection(DB_URL, DB_USERNAME, DB_PASSWORD);
    }

    public static void close(Connection con, PreparedStatement pstmt, ResultSet rs) {
        try {
            if (rs != null) {
                rs.close();
            }

            if (pstmt != null) {
                pstmt.close();
            }

            if (con != null) {
                con.close();
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}

Related

  1. query(String sql)
  2. queryAll(String sql, List params)
  3. readMapListBySQL(String driverClass, String host, String port, String database, String user, String password, String sql)
  4. removeById(int Id)
  5. searchForItemId(String item)
  6. tablesOk(String url, String user, String password)

  7. HOME | Copyright © www.java2s.com 2016