java實現將遠程數據ftp上傳到本地,並存入到mysql數據庫裏

1、Config

package com.lianlife.sync;


import java.text.SimpleDateFormat;

import java.util.Date;


public class Config {

public static final String ftpPath="/PIftp/Yzps/ps001/ps";

//public static final String ftpPath="/PIftp/test01/ps";

public static final String c1 = "17:30:00";

public static final  String c2 = "17:29:00";

public static final String ftpIP = "10.20.28.138";

public static final int ftpPort = 21;

public static final String ftpuser = "ftpuser";

public static final String ftpassword = "ftpuser";

//public static String localDirPath="H:\\yx1\\yq\\ps20150309";

public static String localDirPath="I:\\影像2\\ps2015030923";

public static String date = "20040901";

public static String date2 = "20150926";

public static final String url = "jdbc:mysql://10.20.28.138:3306/mysql";

public static final String driver = "com.mysql.jdbc.Driver";

public static final String user = "root";

public static final String password = "123";

public static boolean isUploadTimePeriod()

{

SimpleDateFormat df = new SimpleDateFormat("HH:mm:ss");

String timenow = df.format(new Date());

if (timenow.compareTo(Config.c1) > 0

|| timenow.compareTo(Config.c2) < 0){

return true;

}

return false ;

}

}

2、DbUtil

package com.lianlife.sync;


import java.sql.Connection;

import java.sql.DriverManager;

import java.sql.PreparedStatement;

import java.sql.ResultSet;


public class DbUtil {

public static Connection getConnection()

{

       try {

      Class.forName(Config.driver);//指定連接類型

} catch (Throwable e) {

throw new RuntimeException(e);

}

       

try {

return DriverManager.getConnection(Config.url, Config.user, Config.password);//獲取連接

} catch (Throwable e) {

e.printStackTrace();

try {

return DriverManager.getConnection(Config.url, Config.user, Config.password);//獲取連接

} catch (Throwable e2) {

e2.printStackTrace();

try {

return DriverManager.getConnection(Config.url, Config.user, Config.password);//獲取連接

} catch (Throwable e3) {

throw new RuntimeException(e3);

}

}

}

}

public static  void close(Connection c)

{

if(c!=null)

{

try {

c.close();

} catch (Throwable e) {

 

e.printStackTrace();

}

}

}

public static  void close(PreparedStatement c)

{

if(c!=null)

{

try {

c.close();

} catch (Throwable e) {

 

e.printStackTrace();

}

}

}

public static  void close(ResultSet c)

{

if(c!=null)

{

try {

c.close();

} catch (Throwable e) {

 

e.printStackTrace();

}

}

}

}

3、

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章