我已经计划了一个R代码,该代码将从链接下载文件并更新MY SQL数据库。
当我手动触发代码时,它运行正常。
但是,在任务计划程序上,日志显示代码正在执行,但是数据库未更新。
我尝试了多种方法,但没有任何效果。
关于我可能会缺少的任何想法/建议吗?
library(RSelenium)
library(seleniumPipes)
library(rvest)
library(httr)
library(RCurl)
library(XML)
library(data.table)
library(janitor)
library(tidyr)
library(splitstackshape)
library(xtable)
unlink("c:\\Users\\user\\Downloads\\ticket_results.csv")
browseURL("download link")
Sys.sleep(10)
Tickets1 <- read.csv("c:\\Users\\user\\Downloads\\ticket_results.csv",
header = TRUE, stringsAsFactors = F, check.names = F)
Tickets1$`Case ID` <- paste0("0",Tickets1$`Case ID`)
Tickets1 <- as.data.frame(Tickets1)
Tickets <- Tickets1
Sys.sleep(10)
unlink("c:\\Users\\user\\Downloads\\ticket_results.csv")
browseURL("link download 2")
Sys.sleep(10)
Tickets1 <- read.csv("c:\\Users\\user\\Downloads\\ticket_results.csv",
header = TRUE, stringsAsFactors = F, check.names = F)
Tickets1$`Case ID` <- paste0("0",Tickets1$`Case ID`)
Tickets1 <- as.data.frame(Tickets1)
Tickets <- rbind(Tickets,Tickets1)
Sys.sleep(10)
library(dbConnect)
library(RMySQL)
iConn <- RMySQL::dbConnect(
RMySQL::MySQL(),
host = 'xxxx',
port = xxxx,
dbname = 'xxxx',
user = 'xxxx',
password = 'xxxx'
)
最后更新
RMYSQL::dbWriteTable(iConn, 'table_to_update', as.data.frame(Tickets),overwrite
=T row.names=F,
field.type=list(CaseID='varchar(20)',
Description='varchar(100)')