Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.sql.*;
- public class SQLiteJDBC_n_n {
- public static void main(String args[]) {
- InnerJoin();
- }
- public static void InnerJoin(){
- Connection c = null;
- Statement stmt = null;
- try {
- Class.forName("org.sqlite.JDBC");
- c = DriverManager.getConnection("jdbc:sqlite:C:\\Users\\GC\\Desktop\\DB e protocolli\\PRIMO\\SQLjava.db");
- c.setAutoCommit(false);
- System.out.println("Database aperto in modo corretto.");
- stmt = c.createStatement();
- ResultSet rs = stmt.executeQuery("SELECT Alunno.Nome, Alunno.Cognome, Alunno.N_Registro, Alunno.Media, Prof.Nome AS NomeProf, Prof.Cognome AS CognomeProf, Prof.Materia, Prof.ID FROM Alunno INNER JOIN Insegna ON Alunno.N_Registro = Insegna.N_Registro INNER JOIN Prof ON Prof.ID = Insegna.ID;");
- while ( rs.next() ) {
- String nome = rs.getString("Nome");
- String cognome = rs.getString("Cognome");
- Integer n_registro = rs.getInt("N_Registro");
- Integer media = rs.getInt("Media");
- /*Integer n_registroRelazione = rs.getInt("N_RegistroRelazione");
- Integer idRelazione = rs.getInt("IDRelazione");*/
- String nomeprof = rs.getString("NomeProf");
- String cognomeprof = rs.getString("CognomeProf");
- String materia = rs.getString("Materia");
- Integer id = rs.getInt("ID");
- System.out.println( "NOME = " + nome );
- System.out.println( "COGNOME = " + cognome );
- System.out.println( "N_Registro = " + n_registro );
- System.out.println( "Media = " + media );
- /*System.out.println( "N_RegistroRelazione = " + n_registroRelazione );
- System.out.println( "IDRelazione = " + idRelazione );*/
- System.out.println( "NomeProf = " + nomeprof );
- System.out.println( "CognomeProf = " + cognomeprof );
- System.out.println( "Materia = " + materia );
- System.out.println( "ID = " + id );
- System.out.println();
- }
- rs.close();
- stmt.close();
- c.close();
- } catch ( Exception e ) {
- System.err.println( e.getClass().getName() + ": " + e.getMessage() );
- System.exit(0);
- }
- System.out.println("Operazione svolta con successo.");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement