Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Setting dynamic column value in PreparedStatement

Reply
Thread Tools

Setting dynamic column value in PreparedStatement

 
 
Anythingcan
Guest
Posts: n/a
 
      10-25-2004
Hi gurus,

The following two sql statements delete all entries in a database.

1) DELETE FROM table_name;
2) DELETE FROM table_name WHERE column = column;

However, I would like my java code to only make use of option 2 so
that I can use it to delete all entries AND specific entry using a
PreparedStament, as follows:

con.prepareStatement("DELETE FROM table_name WHERE column = ?");

If I want to delete 'a', the code would be:

pstmt.setSring(1, "a");
pstmt.execute();

But what is the code to delete all the entries.

Is it the setRef(..) method? If yes, how? If not, how?

Thanks.
 
Reply With Quote
 
 
 
 
Sudsy
Guest
Posts: n/a
 
      10-25-2004
Anythingcan wrote:
> Hi gurus,
>
> The following two sql statements delete all entries in a database.
>
> 1) DELETE FROM table_name;
> 2) DELETE FROM table_name WHERE column = column;
>
> However, I would like my java code to only make use of option 2 so
> that I can use it to delete all entries AND specific entry using a
> PreparedStament, as follows:
>
> con.prepareStatement("DELETE FROM table_name WHERE column = ?");
>
> If I want to delete 'a', the code would be:
>
> pstmt.setSring(1, "a");
> pstmt.execute();
>
> But what is the code to delete all the entries.


This isn't a Java question; it's pure SQL. And while there are
wildcards in standard SQL, it's not going to help you in this
case. Your equivalency test will fail with wildcards. You'd have
to use the LIKE qualifier, which might have other unintended
consequences if you incorporate that into the prepare statement.

Better to refer to a good SQL reference tome.

--
Java/J2EE/JSP/Struts/Tiles/C/UNIX consulting and remote development.

 
Reply With Quote
 
 
 
 
John B. Matthews
Guest
Posts: n/a
 
      10-25-2004
In article <(E-Mail Removed)>,
Sudsy <(E-Mail Removed)> wrote:

> Anythingcan wrote:
> > Hi gurus,
> >
> > The following two sql statements delete all entries in a database.
> >
> > 1) DELETE FROM table_name;
> > 2) DELETE FROM table_name WHERE column = column;
> >
> > However, I would like my java code to only make use of option 2 so
> > that I can use it to delete all entries AND specific entry using a
> > PreparedStament, as follows:
> >
> > con.prepareStatement("DELETE FROM table_name WHERE column = ?");
> >
> > If I want to delete 'a', the code would be:
> >
> > pstmt.setSring(1, "a");
> > pstmt.execute();
> >
> > But what is the code to delete all the entries.

>
> This isn't a Java question; it's pure SQL. And while there are
> wildcards in standard SQL, it's not going to help you in this
> case. Your equivalency test will fail with wildcards. You'd have
> to use the LIKE qualifier, which might have other unintended
> consequences if you incorporate that into the prepare statement.
>
> Better to refer to a good SQL reference tome.


Indeed. As an alternative, look at the "TRUNCATE table_name" command.

--
John
----
jmatthews at wright dot edu
www dot wright dot edu/~john.matthews/
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Pump data by row and column to dynamic created column in gridview johnsonlim026 ASP .Net 0 02-27-2010 05:29 PM
GridView - Setting the text of the 'select' column to the value of another column Greg Smith ASP .Net 0 04-12-2007 03:11 PM
GridView - Setting the text of the 'select' column to the value of another column Greg Smith ASP .Net Web Controls 0 04-12-2007 02:40 PM
setting Column width of Template Column in Datagrid.. Charleees ASP .Net 2 06-20-2006 12:52 PM
Move bound column to right of dynamic column in datagrid? John E. ASP .Net 3 03-25-2005 09:19 PM



Advertisments