Solved

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

Posted on 2011-09-26
5
258 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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
Follow this checklist to learn more about the 15 things you should never include in an email signature from personal quotes, animated gifs and out-of-date marketing content.
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

708 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now