Ciao a tutti,
Non so come gestire l'esecuzione di query su diversi db.
Ecco le mie connessioni:
..
Class.forName("org.postgresql.Driver");
cSib = DriverManager.getConnection("jdbcostgresql://localhost/postgres?user=postgres&password=postgres"); //Server SIB
cB1 = DriverManager.getConnection("jdbcostgresql://localhost/DBBiblio1?user=postgres&password=postgres"); //Server Biblio1
cB2 = DriverManager.getConnection("jdbcostgresql://localhost/DBBiblio2?user=postgres&password=postgres"); //Server Biblio2
..
Ma come faccio ad eseguire una query tipo:
..
queryTitolo = "SELECT * FROM biblio1 " +
"WHERE titolo LIKE ? UNION SELECT * " +
"FROM biblio2 WHERE titolo LIKE ?";
..
Dove ovviamente biblio1 sta in DBBiblio1 e biblio2 sta in DBBilbio2, e sono omogenee.
Se le tabelle stanno sullo stesso server non c'è problema, ma se creo 2 server con le stesse tabelle non so come fare per unire quantomeno i risultati.
Con i tentativi che ho fatto trovo solo risultati relativi a una query o l'altra.
Ecco come ho implementato la soluzione ma non va come dico io:
..
queryTitolo1 = "SELECT * FROM biblio1";
queryTitolo2 = "SELECT * FROM biblio2";
preparedstatement = cB1.prepareStatement(queryTitolo1);
preparedstatement = cB2.prepareStatement(queryTitolo2);
..
//unione risultati ???
Grazie un PetaByte di volte!
Marco

ostgresql://localhost/postgres?user=postgres&password=postgres"); //Server SIB
Rispondi quotando
