Groovy insert and select query together using sql server database -
i have issues executing sql server query in groovy code. requirement , need read data table abc.customer , store data temporary table test.
my query :
declare @throughdate datetime, @startdate datetime declare @test table ( test_id char(50) ) set @throughdate = '5-27-2015' set @startdate = dateadd(year, -1, @throughdate) insert @test select test_id abc.customer isnull(create_date, '1-1-1900') between @startdate , @throughdate , datediff(minute, isnull(create_date, '1-1-1900'), isnull(last_login, '1-1-1900')) < 1
i don't have connection issues. can query other tables , data. combination of insert , select not working me.
my groovy code :
def sql=sql.newinstance("jdbc:sqlserver://localhost","test","test","com.microsoft.sqlserver.jdbc.sqlserverdriver") sql.eachrow("""declare @throughdate datetime, @startdate datetime declare @test table(test_id char(50)) set @throughdate = '5-27-2015' set @startdate = dateadd(year,-1,@throughdate) insert @test select test_id abc.customer isnull(create_date,'1-1-1900') between @startdate , @throughdate , datediff(minute,isnull(create_date,\'1-1-1900\'),isnull(last_login,\'1- 1-1900\')) < 1 select test_id @test """){ println "value ${it}" }
the code throwing following exception :
caught: com.microsoft.sqlserver.jdbc.sqlserverexception: statement did not return result set. com.microsoft.sqlserver.jdbc.sqlserverexception: statement did not return result set. @ com.microsoft.sqlserver.jdbc.sqlserverexception.makefromdrivererror(sqlserverexception.java:190) @ com.microsoft.sqlserver.jdbc.sqlserverstatement.doexecutestatement(sqlserverstatement.java:800) @ com.microsoft.sqlserver.jdbc.sqlserverstatement$stmtexeccmd.doexecute(sqlserverstatement.java:689) @ com.microsoft.sqlserver.jdbc.tdscommand.execute(iobuffer.java:5696) @ com.microsoft.sqlserver.jdbc.sqlserverconnection.executecommand(sqlserverconnection.java:1715) @ com.microsoft.sqlserver.jdbc.sqlserverstatement.executecommand(sqlserverstatement.java:180) @ com.microsoft.sqlserver.jdbc.sqlserverstatement.executestatement(sqlserverstatement.java:155) @ com.microsoft.sqlserver.jdbc.sqlserverstatement.executequery(sqlserverstatement.java:616) @ datavisualization.sqlservertest.main(sqlservertest.groovy:104)
it great if 1 me resolve issue.
thanks.
try add "set nocount on" in query statement before first set:
declare @throughdate datetime, @startdate datetime declare @test table(test_id char(50)) set nocount on set @throughdate = '5-27-2015'
sql-server print out text messages each insert/update/select statement without "nocount", break record set.
Comments
Post a Comment