AppletTalk.com Forum Index AppletTalk.com
Java discussions newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

PreparedStatement and DEFAULT

 
Post new topic   Reply to topic    AppletTalk.com Forum Index -> Java and Databases
View previous topic :: View next topic  
Author Message
Tormod Omholt-Jensen
Guest





PostPosted: Wed Apr 21, 2004 1:03 pm    Post subject: PreparedStatement and DEFAULT Reply with quote




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





PostPosted: Wed Apr 21, 2004 1:19 pm    Post subject: Re: PreparedStatement and DEFAULT Reply with quote



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
Display posts from previous:   
Post new topic   Reply to topic    AppletTalk.com Forum Index -> Java and Databases All times are GMT
Page 1 of 1

 
Jump to:  
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


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.