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

x
?
Solved

Checking before doing creation table in the database "JAVA"

Posted on 2006-07-12
8
Medium Priority
?
264 Views
Last Modified: 2010-03-31
I want to write a method to create table (CREATE TABLE …) in the database.
I wrote a method doCreation() to generate SQL create statement.
But, I want to check if tableArrayList.get(1) = “name of table” is already in the database or do the creation.
0
Comment
Question by:javamate06
  • 4
  • 4
8 Comments
 
LVL 86

Expert Comment

by:CEHJ
ID: 17090347
You could do

CREATE OR REPLACE TABLE

if the Sql of your db allows it. Otherwise you will have to query system tables
0
 

Author Comment

by:javamate06
ID: 17113648
If I use:

CREATE OR REPLACE TABLE

I may face a problem in the size of column, I may create table with minmum size and it will not allowed this.  Becuse of I have for every create statment differenet size of the same column.

If there is a way to check the size and take the maximum.
0
 

Author Comment

by:javamate06
ID: 17113726
Can I have the size of the columns that is already defined in the DB?
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 86

Expert Comment

by:CEHJ
ID: 17113742
>>Can I have the size of the columns that is already defined in the DB?

That would be db-specific. Check for your db. You could build your own mapping between column type and size
0
 

Author Comment

by:javamate06
ID: 17113960
I use:

 java.sql

and I want to retrieve the size of the column from “desc tableName“ query because the second column has the type and the size ,
I tried with this code
 
        ResultSet rs = stmt.executeQuery("desc TABLE2");
            ResultSetMetaData rsmd = rs.getMetaData();
           int numberOfColumns = rsmd.getColumnCount();
          
                while(numberOfColumns !=  0)
                {
                 System.out.println(rsmd.getColumDisplaySize(numberOfColumns));
                 numberOfColumns--;
                 }

It gave me
 
ORA-00900 Invalid SQL statement
0
 
LVL 86

Accepted Solution

by:
CEHJ earned 160 total points
ID: 17114130
Try

 ResultSet rs = stmt.executeQuery("describe TABLE2");
0
 

Author Comment

by:javamate06
ID: 17114531
For you information use

select count(1) from tab where tname like 'table name';


if count(1) > 0
then table exit;
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 17120368
:-)
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Suggested Courses

971 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