Java implements the upload of Remote Data Over ftp to the local computer and coexist in the mysql database.

Source: Internet
Author: User

Java implements the upload of Remote Data Over ftp to the local computer and coexist in the mysql database.

1. Configpackage 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; pub Lic static final String ftpuser = "ftpuser"; public static final String ftpassword = "ftpuser"; // public static String localDirPath = "H: \ yx1 \ yq \ ps20150309 "; public static String localDirPath =" I: \ Image 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. DbUtilpackage com. lianlife. sync; import java. SQL. C Onnection; import java. SQL. driverManager; import java. SQL. preparedStatement; import java. SQL. resultSet; public class DbUtil {public static Connection getConnection () {try {Class. forName (Config. driver); // specify the connection type} catch (Throwable e) {throw new RuntimeException (e);} try {return DriverManager. getConnection (Config. url, Config. user, Config. password); // get connection} catch (Throwable e) {e. printStackTrace (); try {ret Urn DriverManager. getConnection (Config. url, Config. user, Config. password); // get connection} catch (Throwable e2) {e2.printStackTrace (); try {return DriverManager. getConnection (Config. url, Config. user, Config. password); // get Connection} 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 ();}}}}

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.