/**
 *
 */
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 {

    /**
     * 
     * @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";
        
//        args = new String[]{"2011-1212-"};
        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) {}
        }
    }

}
