java中的接口是类吗
477
2022-12-30
Java通过python命令执行DataX任务的实例
1.安装datax
2.安装python并配置环境变量
3.把mysql2odps.json文件放在datax安装目录的job文件夹下
4.运行Test.java测试
mysql2odps.json文件:
{
"job": {
"content": [
{
"reader": {
"name": "mysqlreader",
"parameter": {
"username": "$username",
"password": "$password",
"where": "optime>='$startDate $startTime' and ophttp://time<'$endDate $endTime'",
"column": ["id","xm"],
"connection": [
{
"table": [
"test"
],
"jdbcUrl": [
"$jdbcUrl"
]
}
]
}
},
"writer": {
"name": "odpswriter",
"parameter": {
"accessId": "****************",
"accessKey": "******************************",
"column": ["id","xm"],
"odpsServer": "http://service.odps.xxx.com/api",
"partition": "bt=$bt,region=$region",
"project": "dst_project_name",
"table": "test"
}
}
}
],
"setting": {
"speed": {
"channel": 10
}
}
}
}
测试程序(我的datax安装路径为F盘根目录):
import java.io.BufferedReader;
import java.io.InputStreamReader;
public class Test {
public static void main(String[] args) {
try {
System.out.println("start");
String windowcmd = "cmd /c python F:/datax/bin/datax.py -p \" -Dusername=root -Dpassword=1234 -DjdbcUrl=jdbc:mysql://192.168.1.122:3306/center -Dwhere=left(optime,10)=CURDATE() -Dbt=20171214 -Dregion=beijing \" F:/datax/job/mysql2odps.json";
System.out.println(windowcmd);
Process pr = Runtime.getRuntime().exec(windowcmd);
BufferedReader in = new Buhttp://fferedReader(new InputStreamReader(pr.getInputStream()));
String line;
while ((line = in.readLine()) != null) {
System.out.println(line);
}
in.close();
pdXQhKKEr.waitFor();
System.out.println("end");
} catch (Exception e) {
e.printStackTrace();
}
}
}
版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。
发表评论
暂时没有评论,来抢沙发吧~