dreampolice
Technical User
I have methods that call the same ResultSet statement and was wondering if I can put the ResultSet into a method and call it instead:
This would be better:
Code:
public int mymethod(MyBean theobject)
{
//db connection part here
String query = "SELECT EmailAddress FROM UserT " +
"WHERE firstname = '" + theobject.getFirstname () + "' and lastname = '" + theobject.getLastname() + "'";
Statement statement = connection.createStatement();
ResultSet results = statement.executeQuery(query);
...
}
public int anothermethod(MyBean theobject)
{
//db connection part here
String query = "SELECT EmailAddress FROM UserT " +
"WHERE firstname = '" + theobject.getFirstname () + "' and lastname = '" + theobject.getLastname() + "'";
Statement statement = connection.createStatement();
ResultSet results = statement.executeQuery(query);
...
}
This would be better:
Code:
public int mymethod(MyBean theobject)
{
//db connection part here
//method call here
...
}
public int anothermethod(MyBean theobject)
{
//db connection part here
//method call here
...
}