Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: check a list based on the cell if there is a value

  1. #1
    Member
    Join Date
    Jun 2017
    Posts
    46
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default check a list based on the cell if there is a value

    A question.
    Since in excel I always have a list of string values.
    If in the list there exists id and plaque fammi update, if there is no id and plaque, give me the insert. Do you think it's okay what I did? what needs to be fixed?

    for (i = 0; i < 280; i++) {
    					// Se il valore NON E' NULL: ID E TARGA FACCIO L'UPDATE
    					if ((listaIdVeicolo.get(i) != null || listaIdVeicolo.get(i).isEmpty() == true)
    							&& (lista_targa.get(i) != null || lista_targa.get(i).isEmpty()) == true) {
    						System.out.print("UPDATE veicolo" + " set" + " veicolo.data_fine_validita = " + "'"
    								+ lista_data_fine_validita.get(i) + "'" + "," + " veicolo.data_inizo_validita = " + "'"
    								+ lista_data_inizio_validita.get(i) + "'" + "," + " veicolo.classe_euro = " + "'"
    								+ lista_classe_euro.get(i) + "'" + "," + " veicolo.tipo_di_possesso= " + "'"
    								+ lista_tipo_di_possesso.get(i) + "'" + " where veicolo.id = " + "'"
    								+ listaIdVeicolo.get(i) + "'" + " and" + " veicolo.targa = " + "'" + lista_targa.get(i)
    								+ "'" + ";\n");
     
    						fw.write("UPDATE veicolo" + " set" + " veicolo.data_fine_validita = " + "'"
    								+ lista_data_fine_validita.get(i) + "'" + "," + " veicolo.data_inizo_validita = " + "'"
    								+ lista_data_inizio_validita.get(i) + "'" + "," + " veicolo.classe_euro = " + "'"
    								+ lista_classe_euro.get(i) + "'" + "," + " veicolo.tipo_di_possesso= " + "'"
    								+ lista_tipo_di_possesso.get(i) + "'" + " where veicolo.id = " + "'"
    								+ listaIdVeicolo.get(i) + "'" + " and" + " veicolo.targa = " + "'" + lista_targa.get(i)
    								+ "'" + ";\n");
    					}
    					else {
    						System.out.print(
    								"insert into veicolo (create_date,modified_date,uuid, classe_euro, codice_cliente_originario,contratto,data_fine_validita,data_inizio_validita, disponibilita,nazione,targa,tipo_di_possesso, id_anagrafica) "
    										+ "VALUES (" + "'" + timestamp + "'" + "," + "'" + timestamp + "'" + "," + "'"
    										+ listaveicoloUuid.get(i) + "'" + "," + "'" + lista_classe_euro.get(i) + "'"
    										+ "," + "'" + listaCodiceClienteOriginario.get(i) + "'" + "," + "'"
    										+ listaContratto.get(i) + "'" + "," + "'"
    										+ lista_data_fine_validita.get(i).toString() + "'" + "," + "'"
    										+ lista_data_inizio_validita.get(i).toString() + "'" + "," + "'"
    										+ listadisponibilita.get(i) + "'" + "," + "'" + listaNazione.get(i) + "'" + ","
    										+ "'" + lista_targa.get(i) + "'" + "," + "'" + lista_tipo_di_possesso.get(i)
    										+ "'" + "," + "'" + listaAnagrafica.get(i) + "'" + ")" + ";\n");
     
    						fw.write(
    								"insert into veicolo (create_date,modified_date,uuid, classe_euro, codice_cliente_originario,contratto,data_fine_validita,data_inizio_validita, disponibilita,nazione,targa,tipo_di_possesso, id_anagrafica) "
    										+ "VALUES (" + "'" + timestamp + "'" + "," + "'" + timestamp + "'" + "," + "'"
    										+ listaveicoloUuid.get(i) + "'" + "," + "'" + lista_classe_euro.get(i) + "'"
    										+ "," + "'" + listaCodiceClienteOriginario.get(i) + "'" + "," + "'"
    										+ listaContratto.get(i) + "'" + "," + "'"
    										+ lista_data_fine_validita.get(i).toString() + "'" + "," + "'"
    										+ lista_data_inizio_validita.get(i).toString() + "'" + "," + "'"
    										+ listadisponibilita.get(i) + "'" + "," + "'" + listaNazione.get(i) + "'" + ","
    										+ "'" + lista_targa.get(i) + "'" + "," + "'" + lista_tipo_di_possesso.get(i)
    										+ "'" + "," + "'" + listaAnagrafica.get(i) + "'" + ")" + ";\n");
     
    					}
     
    				}

  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,162
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: check a list based on the cell if there is a value

    Do you think it's okay what I did?
    Is there a problem with the code?
    Does it do what you want?
    If there are errors or the results are not what you want please explain.


    what needs to be fixed?
    for (i = 0; i < 280; i++)
    The 280 should be replaced with a variable or a method that gets the length of the list being processed.

    If the String being sent to the print method and the write method is identical, then it should not be coded two times. Create a String with the data to print and pass that String to the print and write methods.
      String toPrint = "the stuff to print";   // build String here
      System.out.print(toPrint);
      fw.write(toPrint);
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Replies: 4
    Last Post: March 24th, 2014, 03:59 PM
  2. Knapsack problem , check if matrix can fill list of smaller matrix list.
    By ofirattia in forum What's Wrong With My Code?
    Replies: 1
    Last Post: December 8th, 2012, 01:20 PM

Tags for this Thread