Buggy code:
public class HospitalDatabase implements ActionListener { private BufferedReader in = new BufferedReader ( new InputStreamReader ( System . in ) ) ; private Connection con ; private int loginAttempts = 0 ; private JTextField usernameField ; private JPasswordField passwordField ; private JFrame mainFrame ; public HospitalDatabase ( ) { } private void oracleLogin ( ) { } private boolean connect ( String username , String password ) { } public void actionPerformed ( ActionEvent e ) { } private void showMenu ( ) { } private void generateBill ( ) { } private void findDoctorsOfSpecialization ( ) { } private void findAveMedCost ( ) { } private void findDoctorsWhoPerformedInAllOpRooms ( ) { } private void getProceduresForDoctor ( ) { } private void getProceduresForPatient ( ) { } private void findPatientsInRecovery ( ) { } private void findAvailableRecoveryRoomBeds ( ) { } private void checkOperatingRooms ( ) { } private void getProceduresOnDate ( ) { } private void getMaxMinAveMedDoc ( ) { try { System . out . print ( "\nEnter<seq2seq4repair_space>\'1\'<seq2seq4repair_space>to<seq2seq4repair_space>find<seq2seq4repair_space>doctor<seq2seq4repair_space>with<seq2seq4repair_space>minimum<seq2seq4repair_space>average<seq2seq4repair_space>medication<seq2seq4repair_space>cost<seq2seq4repair_space>(of<seq2seq4repair_space>those<seq2seq4repair_space>prescribe),<seq2seq4repair_space>or<seq2seq4repair_space>\'2\'<seq2seq4repair_space>for<seq2seq4repair_space>maximum.\n" ) ; int choice = 0 ; boolean cond = true ; while ( cond ) { try { choice = Integer . parseInt ( in . readLine ( ) ) ; if ( ( choice >= 1 ) && ( choice <= 2 ) ) { cond = false ; } else { System . out . println ( "Please<seq2seq4repair_space>enter<seq2seq4repair_space>an<seq2seq4repair_space>available<seq2seq4repair_space>option!" ) ; } } catch ( NumberFormatException e ) { System . out . println ( "Your<seq2seq4repair_space>input<seq2seq4repair_space>must<seq2seq4repair_space>contain<seq2seq4repair_space>valid<seq2seq4repair_space>integers<seq2seq4repair_space>only!<seq2seq4repair_space>Try<seq2seq4repair_space>again:<seq2seq4repair_space>" ) ; } } String maxMin = "" ; if ( choice == 1 ) { maxMin = "MIN" ; } else if ( choice == 2 ) { maxMin = "MAX" ; } <START_BUG> String query = ( ( "SELECT<seq2seq4repair_space>D.do_name,<seq2seq4repair_space>A.AveCost<seq2seq4repair_space>FROM<seq2seq4repair_space>Doctors<seq2seq4repair_space>D,<seq2seq4repair_space>(SELECT<seq2seq4repair_space>P.do_id,<seq2seq4repair_space>AVG(M.cost)<seq2seq4repair_space>AS<seq2seq4repair_space>AveCost<seq2seq4repair_space>" + ( "FROM<seq2seq4repair_space>Medications<seq2seq4repair_space>M,<seq2seq4repair_space>Prescribes<seq2seq4repair_space>P,<seq2seq4repair_space>Doctors<seq2seq4repair_space>D<seq2seq4repair_space>WHERE<seq2seq4repair_space>M.med_id=P.med_id<seq2seq4repair_space>GROUP<seq2seq4repair_space>BY<seq2seq4repair_space>P.do_id)<seq2seq4repair_space>A<seq2seq4repair_space>" + "WHERE<seq2seq4repair_space>A.do_id=D.do_id<seq2seq4repair_space>AND<seq2seq4repair_space>A.AveCost='" ) ) + maxMin ) + "'(A.AveCost)" ; <END_BUG> Statement stmt = con . createStatement ( ) ; ResultSet rs = stmt . executeQuery ( query ) ; ResultSetMetaData rsMetaData = rs . getMetaData ( ) ; int numCols = rsMetaData . getColumnCount ( ) ; ArrayList < String > availableColumns = new ArrayList < String > ( ) ; ArrayList < Integer > columnWidths = new ArrayList < Integer > ( ) ; for ( int i = 1 ; i <= numCols ; i ++ ) { int displaySize = ( rsMetaData . getColumnDisplaySize ( i ) ) + 20 ; String columnName = rsMetaData . getColumnName ( i ) ; availableColumns . add ( columnName ) ; columnWidths . add ( displaySize ) ; System . out . printf ( ( ( ( ( "%-" + displaySize ) + "." ) + displaySize ) + "s" ) , columnName ) ; } System . out . println ( "\n" ) ; while ( rs . next ( ) ) { for ( int i = 0 ; i < numCols ; i ++ ) { String columnName = availableColumns . get ( i ) ; Integer columnSize = columnWidths . get ( i ) ; String rowData = rs . getString ( columnName ) ; System . out . printf ( ( ( ( ( "%-" + columnSize ) + "." ) + columnSize ) + "s" ) , rowData ) ; } System . out . println ( "\n" ) ; } stmt . close ( ) ; } catch ( IOException e ) { System . out . println ( "IOException!" ) ; } catch ( SQLException ex ) { System . out . println ( ( "Message:<seq2seq4repair_space>" + ( ex . getMessage ( ) ) ) ) ; } } private void runSql ( ) { } private void chooseTable ( ) { } private void modifyTable ( String tableName ) { } private void insertIntoTable ( String tableName ) { } private void deleteFromTable ( String tableName ) { } private void updateTableValue ( String tableName ) { } private void showTableData ( String tableName ) { } private String getPrimaryKey ( String tableName ) { } private String getColumnType ( String tableName , String columnName ) { } private ArrayList < String > getTableColumns ( String tableName ) { } public static void main ( String [ ] args ) { } }

Fix:
String query = ( ( "SELECT<seq2seq4repair_space>D.do_name,<seq2seq4repair_space>A.AveCost<seq2seq4repair_space>FROM<seq2seq4repair_space>Doctors<seq2seq4repair_space>D,<seq2seq4repair_space>(SELECT<seq2seq4repair_space>P.do_id,<seq2seq4repair_space>AVG(M.cost)<seq2seq4repair_space>AS<seq2seq4repair_space>AveCost<seq2seq4repair_space>" + ( "FROM<seq2seq4repair_space>Medications<seq2seq4repair_space>M,<seq2seq4repair_space>Prescribes<seq2seq4repair_space>P,<seq2seq4repair_space>Doctors<seq2seq4repair_space>D<seq2seq4repair_space>WHERE<seq2seq4repair_space>M.med_id=P.med_id<seq2seq4repair_space>GROUP<seq2seq4repair_space>BY<seq2seq4repair_space>P.do_id)<seq2seq4repair_space>A<seq2seq4repair_space>" + "WHERE<seq2seq4repair_space>A.do_id=D.do_id<seq2seq4repair_space>AND<seq2seq4repair_space>A.AveCost=" ) ) + maxMin ) + "(A.AveCost)" ;