Select in two tables. How to return a single list?

1

I have a Process table, with basic data and other ProcessesDestaque, with more specific data. I need to make a select that calls some columns of the basic data and some of the specific data. I tried to make a list, but I can only call the data from just one table.

In the first Process table, I have the following columns: codGeral,classeProc, numProc, autorProc, ResumoProc .

The ProcessesDestaque table has the following columns: codDest, codGeral(chave estrangeira), ementaProc, dispProc .

The listarDest method looks like this:

public List listarDest()
{
List lst= new ArrayList<>();

List lstDest = newArrayList<>();
try
{
stmt = con.prepareStatement(“SELECT codigoGeral.Processos, classe.Processos, numProc.Processos, autor.Processos, codDest.ProcessosDestaques, ementaProc.ProcessosDestaque FROM ProcessosDestaque JOIN Processos ON ProcessosDestaque.codGeral = Processos.codGeral”);

rs = stmt.executeQuery();

while(rs.next())

{

ProcDestaques procdestaques = new ProcDestaques();

Proc proc = new Proc();

procdestaques.setCodDest(rs.getInt(1));

procdestaques.setCodGeral(rs.getInt(2));

proc.setClasse(rs.getString(3));

proc. setNumProc(rs.getString(4));

proc.setAutor(rs.getString(5));

procdestaques.setEmentaProc(rs.getString(6));

lstDest.add(procdestaques);

lst.add(proc);

}

stmt.execute();

rs.close();

con.close();

}

catch (SQLException e)

{

throw new RuntimeException(e);

}

return lstDest;

}

Does anyone have any idea how to do the select return the data of the two tables?

    
asked by anonymous 04.02.2018 / 01:44

1 answer

0

Friend you can use query native, and query would be like this more or less:

SELECT processo.codGeral, processo.classe, processo.numProc, processo.autor, detalhe.codDest,  processo.numProc FROM Processos processo, ProcessosDestaque detalhe WHERE processo.codGeral = detalhe.codGeral

I hope I have helped.

    
12.03.2018 / 22:26