Restart an auto_increment using java [duplicate]

-3

Good afternoon I'm creating a website with java I'm uploading an excel file to a jsp to save it in MySQL at the moment I am reading the file in it I am saving it in an ArrayList to save it in MySQL alphabetically ordered, the table in MySQL where the saved file will be has a primary key composed of three columns and one is auto_increment, what I need is that when I save it in MySQL the auto_incremente reboot me for each example record

 1    andrés
 2    andres
 3    andrés
 1    david
 2    david
 1    Fernando
 2    Fernando
 3    Fernando
 4    Fernando

I upload the part where I'm reading the excel I am very new in this if someone can help me I would appreciate it very much

package models;

import dao.TablaJiraDao;
import dao.TablaNovedadesDao;
import dao.TablaNovedadEmpleadoDao;
import entidades.TablaJira;
import entidades.TablaNovedadEmpleado;
import entidades.TablaNovedades;
import java.io.FileInputStream;
import java.io.IOException;
import java.sql.Date;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;

public class ReadExcel2 {

    public static void leerArchivoExcel2(FileInputStream inputStream) throws IOException {

        XSSFWorkbook workbook = new XSSFWorkbook(inputStream);
        Sheet firstSheet = workbook.getSheetAt(0);

        Row fila;
        List<TablaJira> lst = new ArrayList<>();
        TablaJira ji;

        for (int i = 1; i < firstSheet.getLastRowNum(); i++) {

            fila = firstSheet.getRow(i);

            ji = new TablaJira();

            for (int j = 0; j < fila.getLastCellNum(); j++) {
                Cell celda = fila.getCell(j);

                if (j == 0) {

                    if (celda == null || celda.getCellType() == Cell.CELL_TYPE_BLANK) {
                        break;
                    }

                }

                switch (j) {

                    case 0:
                        if (celda.getCellType() == Cell.CELL_TYPE_STRING) {
                            ji.setProyecto(celda.getStringCellValue());

                        }

                        //   n.setNovedad(celda.getStringCellValue());
                        break;

                    case 1:
                        if (celda.getCellType() == Cell.CELL_TYPE_STRING) {
                            ji.setTipo(celda.getStringCellValue());
                        }
                        //ne.setFecha_inicio(celda.getStringCellValue());
                        break;

                    case 2:
                        if (celda.getCellType() == Cell.CELL_TYPE_STRING) {
                            ji.setClave(celda.getStringCellValue());
                        }
                        //ne.setFecha_fin(celda.getStringCellValue());

                        break;

                    case 3:
                        if (celda.getCellType() == Cell.CELL_TYPE_STRING) {
                            ji.setTitulo(celda.getStringCellValue());
                        }
                        //ne.setAño(celda.getStringCellValue());

                        break;
                    case 4:
                        if (celda.getCellType() == Cell.CELL_TYPE_STRING) {
                            ji.setNombres(celda.getStringCellValue());

                            // System.out.println(celda.getStringCellValue());
                        }
                        /*           String des = ji.getNombres();

                        List<String> order = new ArrayList<>();
                        order.add(des);
                         Collections.sort(order);
                         order.forEach((item) -> {
                             System.out.println(item);
                });*/

                        //order.forEach((nombre) -> {
                        //  System.out.println(nombre);
                        //});
                        /* String des = "";
                        des = ji.getNombres();
                        order = des.split("");

                         Arrays.sort(order);*/
 /* for (int n = 0; n < order.length; n++) {
                System.out.println(n+ ",");
                }*/
                        break;
                    case 5:
                        if (celda.getCellType() == Cell.CELL_TYPE_NUMERIC) {
                            ji.setTiempo_horas((int) celda.getNumericCellValue());
                        }

                        //else if (celda.getCellType()== Cell.CELL_TYPE_STRING){
                        //ne.setHoras(celda.getStringCellValue());
                        break;
                }
            }

            //Se guardan los datos por cada fila
            //guardarTablaNovedadEmpleado(ne);
            //guardarTablaNovedades(n);

            if (ji.getNombres() != null) {
                lst.add(ji);

               /*String nombres=ji.getNombres();
                if (nombres!=nombre_ant){
                con=1;

                }else{
                con++;
                   nombre_ant=nombres;
                }*/




            }

        }

        Collections.sort(lst, TablaJira.NameComparator);

//                new Comparator<TablaJira>() {
//            @Override
//            public int compare(TablaJira tb1, TablaJira tb2)
//            {
//                return tb2.getNombres().compareTo(tb1.getNombres());
//            }
//        });
        lst.forEach(ReadExcel2::guardarTblJira);

    }

    private static void guardarTblJira(TablaJira ji) {
        TablaJiraDao dao = new TablaJiraDao();
        dao.insertarTablaJira(ji);

    }
    
asked by victormbrt 05.12.2016 в 23:39
source

1 answer

1

You should think about removing the auto_increment of that field. It is assumed that the behavior should be like this, that it will automatically increase. You should calculate the value instead of leaving it automatic.

    
answered by 06.12.2016 в 00:08