Navigation

    精算后花园

    • Register
    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    1. Home
    2. bengbengbeng
    B
    • Profile
    • Following
    • Followers
    • Topics
    • Posts
    • Best
    • Groups

    bengbengbeng

    @bengbengbeng

    0
    Reputation
    1
    Posts
    1
    Profile views
    0
    Followers
    0
    Following
    Joined Last Online

    bengbengbeng Follow

    Best posts made by bengbengbeng

    This user hasn't posted anything yet.

    Latest posts made by bengbengbeng

    • RE: 【快乐自动化】如何用R连接数据库并批量导入数据

      在操作到第三步的时候,我这边报了一个错,报错信息:
      An error occurred:
      Error: Cannot pass NA to dbQuoteIdentifier()
      Finally done!
      An error occurred:
      Error in dbExistsTable(conn, name): 不是所有的length(name) == 1都是TRUE

      code如下:

      > path = "D:\\GroupP" #这里替换成自己的路径
      > LenPath = nchar(path)
      > filenames <- list.files(path , pattern="*.csv", full.names=TRUE)
      > ldf <- lapply(filenames, read.csv)
      > res <- lapply(ldf, summary)
      > names(res) <- substr(filenames,LenPath+1, LenPath + 3) #这里要根据自己的文件名改变长度
      
      > library(DBI)
      > library(odbc)
      > con <- dbConnect(odbc::odbc(), 
                    Driver = "SQL Server", 
                   Server = "shenjing", #这里替换成自己的Server名字 
                   Database = "Group_Bussiness", #这里替换成自己的DataBase名字 
                   Trusted_Connection = "True")
      
      > for(i in 1:length(ldf)){
           tryCatch(
               data <-dbWriteTable(con, names(res)[i], data.frame(ldf[i]))
              ,
              error = function(e){
                   message("An error occurred:\n", e)
               },
               warning = function(w){
                   message("A warning occured:\n", w)
               },
               finally = {
                   message("Finally done!")
               })
       }
      

      基础数据路径和文件名如下:
      微信截图_20220523112358.png

      posted in R
      B
      bengbengbeng