Solved

Java JDBC: number of rows returned by a "CREATE TABLE AS SELECT" instruction

Posted on 2011-09-26
5
264 Views
Last Modified: 2012-05-12
Hi,

Executing in Java, on a Oracle database, the sql statement:

int rows = stm.executeUpdate("CREATE TABLE A as select * from MONTHS")

 the table A in created and the int variable "rows" contains the number of written rows in the table.

Executing the same statement in SQL Server, with the correct sintax:

int rows = stm.executeUpdate("SELECT * into A from MONTHS");

The rows variable is "-1".

The different databases implement in a different way that JDBC method and don't return the number of written rows? Is there a way to do that on SQL Server?

Thank you in advance

Antonio Vivalda
0
Comment
Question by:Decisionisti
  • 3
  • 2
5 Comments
 
LVL 47

Expert Comment

by:for_yan
ID: 36599787
what happens if you craete table as select * where rownum = 1

and then run "insert into table_a select *..." in a separate stateemnt - will that one return number of rows?

I guess you even can sya "where rownum = 0";

or you can then truncate this row or delete it

I hope insert into should return number of rows
0
 

Author Comment

by:Decisionisti
ID: 36600063
Yes the insert return the number of rows, but I need it in the "select * into A from MONTHS" sql statement
0
 
LVL 47

Accepted Solution

by:
for_yan earned 500 total points
ID: 36600250
well, if driver does not return correctly...

check if you have the latest driver. maybe they fixed it?

actually I'm even surprised that Oracle does return the number in this case - when you do it
in plain oracle sql comand line client - when you do insert, it reports number of rows inserted,
when you do "create table as..." it repots "Table created"  

separate create and insert will lead to the same result and you'll have number of rows.

Or maybe do the way you want, and before or after make
 select count(*)...
0
 

Assisted Solution

by:Decisionisti
Decisionisti earned 0 total points
ID: 36709055
Ok i'll try to do that, thank you
0
 

Author Closing Comment

by:Decisionisti
ID: 36898843
No comment
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This process describes the steps required to Import and Export data from and to .pst files using Exchange 2010. We can use these steps to export data from a user to a .pst file, import data back to the same or a different user, or even import data t…
This article lists the top 5 free OST to PST Converter Tools. These tools save a lot of time for users when they want to convert OST to PST after their exchange server is no longer available or some other critical issue with exchange server or impor…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question