 |
AppletTalk.com Java discussions newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Tormod Omholt-Jensen Guest
|
Posted: Wed Apr 21, 2004 1:03 pm Post subject: PreparedStatement and DEFAULT |
|
|
I have a column in a table as follows
create table test(
a varchar2(12) default 'def' not null
)
I would like to write Java code, that examine a variable, if the var is
null, the default value should be used. I was hoping to write
something like this :
public void insert(String value){
PreparedStatement ps = connection.prepareStatement("insert into test values(?)");
if(value == null){
ps.setDefault(1, Types.VARCHAR);
}
else{
ps.setString(1, value);
}
ps.executeUpdate();
...
}
However, there is no setDefault()-method in the PreparedStatement class.
Any ideas on how to solve this in an elegant way?
Regards Tormod Omholt-Jensen
|
|
| Back to top |
|
 |
Chris Smith Guest
|
Posted: Wed Apr 21, 2004 1:19 pm Post subject: Re: PreparedStatement and DEFAULT |
|
|
Tormod Omholt-Jensen wrote:
| Quote: | create table test(
a varchar2(12) default 'def' not null
)
|
[...]
| Quote: | However, there is no setDefault()-method in the PreparedStatement class.
Any ideas on how to solve this in an elegant way?
|
To use the default value, you can't specify that value as a parameter.
That means the structure of the insert statement changes, and you can't
use the same PreparedStatement to do it. You need to use a different
statement depending on whether you wish to use the default value or an
explicit value.
--
www.designacourse.com
The Easiest Way to Train Anyone... Anywhere.
Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|