[JET] Passing parameters from one method to another [message #659786] |
Tue, 15 March 2011 15:38  |
|
Hello everybody,
I want to know if there is a way for my jet template to pass the value of a variable before I execute my project. I'm creating a dynamical mysql database, and I have a main method that creates indexes for every table through a for loop.
<%for (Table table: db.getTables()) {%>
createTable(con,"<%=table.getName()%>","<%=getCreateTableCommand(db,table)%>");
As you can see, this method calls another one:
public static void createTable (Connection con, String tableName, String createTableStatement) throws SQLException {
Statement st = null;
st = con.createStatement();
System.out.println(String.format("Creating table %s.",tableName));
try {
st.executeUpdate(createTableStatement);
} catch (SQLException e) {
if ( e.getErrorCode() == 1050) {
System.out.println(String.format("\tTable %s already exists. Dropped.",tableName));
st.executeUpdate(String.format("DROP TABLE %s",tableName));
System.out.println(String.format("\tCreating table %s.", tableName));
st.executeUpdate("createTableStatement");
}
else {
ServiceMessage.Exception.handle(e);
}
}
st.close();
}
Here, I'm trying to execute the "Create Table" query beforehand and if this table exists, I delete it and create it again. But before dropping the table, I need to delete its constraints/foreign keys, and for that I need the table name so I can use a rutine under jsp tags that would construct me the sentences I need for. My *real* problem is, that I don't know how to send the table name from the first method to createTable method because those methods weren't written under jsp tags java since I'm going to use them after I translate my template, and even if createTable receives the String tableName (which contains the name of the table that I'm currently creating) I can't use it like this:
<% List <String> fk = public List <String> getTablesWithFK (tableName); %>
Because when the template is translating, it doesn't recognize the variable.
Since I can't merge both methods in only one (that would simplify my existence, because I can directly use <%=table.getName()%> as parameter in getTableswithFK()), is there any way I can receive that value from one method to another?
Thanks in advance.
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.02336 seconds