/**
 *
 */
package com.foc.task;

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

import com.foc.conf.GConstants;

/**
 * 
 * @team BBDTEK IT Team
 * @author renmb
 * @version 1.0
 * @time  2017年9月8日
 */
public class AnkeDateMiIdMain {

    /**
     * 获取大于某个时间的最小ID值
     * java -jar jd-anke-minid-2.16.jar "2017-09-08 01:00:00"
     * 文件目录：  /mnt/foc/project/task/dbsounds
     * 导出文件名称： jd-anke-minid-2.16.jar
     * @author renmb
     * @time  2017年9月8日
     * @param args
     */
    public static void main(String[] args) {
        // TODO Auto-generated method stub
        String driver = "com.microsoft.jdbc.sqlserver.SQLServerDriver";
        String url =  GConstants.getValue("anke.database.url", "jdbc:microsoft:sqlserver://10.72.23.187:1433;DatabaseName=edison200");
        String username = GConstants.getValue("anke.database.username", "foctest");
        String password = GConstants.getValue("anke.database.password", "123@abc");
        String tableName = "dbo.cdr";
        
        Connection conn = null;
        ResultSet rs = null;
        PreparedStatement pstmt = null;
        try {
            System.out.println("select MIN(id) AS minid from "+tableName +" WHERE stm>='"+args[0]+"'");
            Class.forName(driver);
            conn = DriverManager.getConnection(url, username, password);
            pstmt = conn
                    .prepareStatement("select MIN(id) AS minid from "+tableName +" WHERE stm>='"+args[0]+"'");
            rs = pstmt.executeQuery();
            if(rs.next()){
                
                System.out.println("最小ID: "+rs.getLong("minid"));
            }
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            try {
                rs.close();
            } catch (Exception e2) {}
            try {
                pstmt.close();
            } catch (Exception e2) {}
            try {
                conn.close();
            } catch (Exception e2) {}
        }
    }

}
