Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2011-09-26
5
Medium Priority
?
296 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 2000 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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

Are you looking for the options available for exporting EDB files to PST? You may be confused as they are different in different Exchange versions. Here, I will discuss some options available.
Take a look at these 6 Outlook Email management tools which can augment the working and performance of Microsoft Outlook to give you a more rewarding emailing experience.
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.
CodeTwo Sync for iCloud (http://www.codetwo.com/sync-for-icloud?sts=6554) automatically synchronizes your Outlook 2016, 2013, 2010 or 2007 folders with iCloud folders available via iCloud Control Panel. This lets you automatically sync them with…
Suggested Courses

972 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