F
francan00
I have methods that call the same ResultSet statement and SQL and was
wondering if I can put them into a method and call the method instead
of repeating the same lines in each one of my methods:
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:
public int mymethod(MyBean theobject)
{
//db connection part here
//method call here
....
}
public int anothermethod(MyBean theobject)
{
//db connection part here
//method call here
....
}
wondering if I can put them into a method and call the method instead
of repeating the same lines in each one of my methods:
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:
public int mymethod(MyBean theobject)
{
//db connection part here
//method call here
....
}
public int anothermethod(MyBean theobject)
{
//db connection part here
//method call here
....
}