0
votes

I come to the situation where I need to insert the integer values in the table with query which is written in R. for Example:

>n1<-20
>n2<-30
>library(DBI)
>library(RMySQL)
>drv<-dbDriver("MySQL")
>con<-dnConnect(drv,user="root",password="sam123",dbname="user")
>dbSendQuery(con,"insert into test values(n1,n2);") # Problem with this lines only

following error I am getting:

Error in mysqlExecStatement(conn, statement, ...) : RS-DBI driver: (could not run statement: Unknown column 'n1' in 'field list')

Please help me out of these problem

2

2 Answers

0
votes

try the paste function to concatenate

 dbSendQuery(con,paste("insert into test values(",n1,",",n2,");",sep=""));
0
votes

Try this:

library(gsubfn)

fn$dbSendQuery( con, "insert into test values($n1, $n2)" )