I am working with JDBC driver and my problem is storing SQL queries in a good place. The point is that it will be making a large number of queries.
Statement s = conn.createStatement ();
s.executeUpdate ("DROP TABLE IF EXISTS animal");
s.executeUpdate (
"CREATE TABLE animal ("
+ "id INT UNSIGNED NOT NULL AUTO_INCREMENT,"
+ "PRIMARY KEY (id),"
+ "name CHAR(40), category CHAR(40))");`
Change to this...
Statement s = conn.createStatement ();
s.executeUpdate (StaticVariables.getDropTableAnimalQuery());
s.executeUpdate (StaticVariables.getCreateTableAnimalQuery());`
... and create special class with static variables
public class StaticVariables {
private static String dropTableAnimalQuery = "DROP TABLE IF EXISTS animal";
private static String createTableAnimalQuery = "CREATE TABLE animal ("
+ "id INT UNSIGNED NOT NULL AUTO_INCREMENT,"
+ "PRIMARY KEY (id),"
+ "name CHAR(40), category CHAR(40))";
public static String getDropTableAnimalQuery() {
return dropTableAnimalQuery;
}
public static String getCreateTableAnimalQuery() {
return createTableAnimalQuery;
}
}
Maybe someone has a better way to solve this