aspose file tools*
The moose likes JDBC and the fly likes How to create table dynamically in JDBC? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "How to create table dynamically in JDBC?" Watch "How to create table dynamically in JDBC?" New topic
Author

How to create table dynamically in JDBC?

sudheer yathagiri kumar
Ranch Hand

Joined: Mar 22, 2011
Posts: 35
hi friends,
i am trying to create table dynamically.
first import requried things.







The above code is work out for a specific fields in create table statement like
create table tablename(sno number(10),sname varchar2(20),sadd varchar2(20));
if the user want to enter String in the place of number and vice versa(number in the place of string ) it may not read by the methods
readLine(),read(),next(),nextLine()...respectively..
here ranges are also specified if user want beyond this range...
please help me to create a record dynamically...

urgent requirment ...
thanks in advance...

[JB: added code tags]
Scott Selikoff
author
Saloon Keeper

Joined: Oct 23, 2005
Posts: 3710
    
    5

You can use PreparedStatements for UPDATE/INSERT/SELECT/DELETE statements, but unfortunately not CREATE (not usually anyway). For those, you just have to construct the SQL yourself.


My Blog: Down Home Country Coding with Scott Selikoff
sudheer yathagiri kumar
Ranch Hand

Joined: Mar 22, 2011
Posts: 35
yah i am using that statements also ...
"create table"+tabname+"(?,?,?)";

here tabname is the tablename which is read dynamically by using scanner class.
here 1st ? ,2nd ?,3rd ? represents sid,sname.sadd respectively for example... we are createing table dynamically na the user dont know the datatype of the field..so it may enter string in place of number and vice versa... how can i solve the problem..

thanks in advance..
Sudheer Bhat
Ranch Hand

Joined: Feb 22, 2011
Posts: 75
If you don't know the datatype, then always create the columns as VARCHAR2. Later, while processing the data, if you are expecting number from column1 then do a to_number on the column1, if you are expecting date, do a to_date on the varchar2 field and so on..
Scott Selikoff
author
Saloon Keeper

Joined: Oct 23, 2005
Posts: 3710
    
    5

sudheer yathagiri kumar wrote:yah i am using that statements also ...
"create table"+tabname+"(?,?,?)";

here tabname is the tablename which is read dynamically by using scanner class.
here 1st ? ,2nd ?,3rd ? represents sid,sname.sadd respectively for example... we are createing table dynamically na the user dont know the datatype of the field..so it may enter string in place of number and vice versa... how can i solve the problem..

thanks in advance..


As I said, you can't use PreparedStatements, you have to construct the SQL string manually.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to create table dynamically in JDBC?