Dynamically decide constant value using java
2 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Sujatha_Telu
Posted On:   Wednesday, June 18, 2003 02:15 PM

Hi I have a database query which I am defining as a constant. But the problem is the tablenames and table columns have to be dynamically put in. i.e say my constant is defined as protected static final String FAILEDSQLEVENTS = "delete from tableowner.tablename where column = 'value' " now the tableowner and the tablename and the column are decided when my java program runs. so This query should look something like "delete from %s.%s where %s = 'value'" where %s could be filled in dynamically... please let me know if this is possible to be accomplished using java??????? Tha   More>>

Hi


I have a database query which I am defining as a constant.

But the problem is the tablenames and table columns have to be dynamically put in.

i.e say my constant is defined as

protected static final String FAILEDSQLEVENTS =
"delete from tableowner.tablename where column = 'value' "



now the tableowner and the tablename and the column are decided when my java program runs.

so This query should look something like


"delete from %s.%s where %s = 'value'"

where %s could be filled in dynamically...


please let me know if this is possible to be accomplished using java???????



Thanks in advance

Sujatha

   <<Less

Re: Dynamically decide constant value using java

Posted By:   Roger_Hand  
Posted On:   Wednesday, June 18, 2003 09:24 PM

In this case there's not a lot of point to defining the query as a constant, since you'll need to be replacing all the key parts of it. Instead just develop it dynamically:

private int DeleteRow(String tableowner, String tablename,
String columnName, String value) {
String sql = "delete from " + tableowner + "." + tablename
+ " where " + columnName + " = '" + value + "'";
int updatedRows = 0;
try {
Statement sqlUpdateStatement = Conn.createStatement();
updatedRows = sqlUpdateStatement.executeUpdate(sql);
} catch (SQLException e) {e.getMessage());}
return updatedRows;
}

Re: Dynamically decide constant value using java

Posted By:   Joe_Millionaire  
Posted On:   Wednesday, June 18, 2003 02:38 PM

Have you looked at using a PreparedStatement?

About | Sitemap | Contact