Solved

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

Posted on 2011-09-26
5
273 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Enroll in May's Course of the Month

May’s Course of the Month is now available! Experts Exchange’s Premium Members and Team Accounts have access to a complimentary course each month as part of their membership—an extra way to increase training and boost professional development.

Question has a verified solution.

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

In this post we will learn different types of Android Layout and some basics of an Android App.
Changing a few Outlook Options can help keep you organized!
Viewers will learn how the fundamental information of how to create a table.
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
Suggested Courses

734 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