executing SQL query with temp tables using 1.6jdk

Posted on

Question :

I created a batch to run a query that has temp tables as the below example

IF OBJECT_ID ('tempdb..#TEMP1') IS NOT NULL
DROP TABLE #TEMP1
select * 
into #TEMP1
from cutomer

IF OBJECT_ID ('tempdb..#TEMP2') IS NOT NULL
DROP TABLE #TEMP2
select *
into #TEMP2 
from shops

select t1.*
from #TEMP1 t1, #TEMP2 t2 where t1.id=t2.id

I am using the Java code below:

PreparedStatement statment = connection.prepareStatement(query);
ResultSet rs = statment.executeQuery();

It is working fine when I use 1.8 JRE, but it is throwing the following exception with 1.6 and I have to use 1.6. I am using sqljdbc4.jar only.

com.microsoft.sqlserver.jdbc.SQLServerException: The statement did not return a result set.

Answer :

Probably could just add a Return 1; to the end of your query batch.

Just a guess out of the dark based on the error message. (I haven’t touched Java in a while, but I’d bet they changed the way that method works between JRE versions.)

Leave a Reply

Your email address will not be published. Required fields are marked *