Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

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

10 Questions to Ask when Buying Backup Software

Choosing the right backup solution for your organization can be a daunting task. To make the selection process easier, ask solution providers these 10 key questions.

Question has a verified solution.

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

If you troubleshoot Outlook for clients, you may want to know a bit more about the OST file before doing your next job. IMAP can cause a lot of drama if removed in the accounts without backing up.
In part one, we reviewed the prerequisites required for installing SQL Server vNext. In this part we will explore how to install Microsoft's SQL Server on Ubuntu 16.04.
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…

688 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