Answer the question
In order to leave comments, you need to log in
How to avoid code duplication in java?
private int getCountLines ()
{
int countLines = 0;
try {
String query = "SELECT COUNT(*) FROM " + tableName + this.where;
Statement stmt = connection.createStatement();
ResultSet resultSet = stmt.executeQuery(query);
resultSet.next();
countLines = resultSet.getInt(1);
} catch (SQLException e) {
e.printStackTrace();
}
return countLines;
}
Answer the question
In order to leave comments, you need to log in
Perhaps bydlokod (if yes, write down), but washed down just such garbage.
private int getCountLines (boolean allElements)
{
int countLines = 0;
try {
String query = "SELECT COUNT(*) FROM " + tableName;
if (allElements) {
query += this.where;
}
Statement stmt = connection.createStatement();
ResultSet resultSet = stmt.executeQuery(query);
resultSet.next();
countLines = resultSet.getInt(1);
} catch (SQLException e) {
e.printStackTrace();
}
return countLines;
}
private int getCountLines ()
{
return getCountLines(true);
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question