Advertisement
Guest User

Untitled

a guest
Feb 27th, 2020
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.30 KB | None | 0 0
  1. import java.sql.*;
  2.  
  3. public class SQLiteJDBC_n_n {
  4. public static void main(String args[]) {
  5. InnerJoin();
  6. }
  7. public static void InnerJoin(){
  8.  
  9. Connection c = null;
  10. Statement stmt = null;
  11.  
  12. try {
  13.  
  14. Class.forName("org.sqlite.JDBC");
  15. c = DriverManager.getConnection("jdbc:sqlite:C:\\Users\\GC\\Desktop\\DB e protocolli\\PRIMO\\SQLjava.db");
  16. c.setAutoCommit(false);
  17. System.out.println("Database aperto in modo corretto.");
  18.  
  19. stmt = c.createStatement();
  20. 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;");
  21. while ( rs.next() ) {
  22. String nome = rs.getString("Nome");
  23. String cognome = rs.getString("Cognome");
  24. Integer n_registro = rs.getInt("N_Registro");
  25. Integer media = rs.getInt("Media");
  26. /*Integer n_registroRelazione = rs.getInt("N_RegistroRelazione");
  27. Integer idRelazione = rs.getInt("IDRelazione");*/
  28. String nomeprof = rs.getString("NomeProf");
  29. String cognomeprof = rs.getString("CognomeProf");
  30. String materia = rs.getString("Materia");
  31. Integer id = rs.getInt("ID");
  32. System.out.println( "NOME = " + nome );
  33. System.out.println( "COGNOME = " + cognome );
  34. System.out.println( "N_Registro = " + n_registro );
  35. System.out.println( "Media = " + media );
  36. /*System.out.println( "N_RegistroRelazione = " + n_registroRelazione );
  37. System.out.println( "IDRelazione = " + idRelazione );*/
  38. System.out.println( "NomeProf = " + nomeprof );
  39. System.out.println( "CognomeProf = " + cognomeprof );
  40. System.out.println( "Materia = " + materia );
  41. System.out.println( "ID = " + id );
  42. System.out.println();
  43. }
  44. rs.close();
  45. stmt.close();
  46. c.close();
  47. } catch ( Exception e ) {
  48. System.err.println( e.getClass().getName() + ": " + e.getMessage() );
  49. System.exit(0);
  50. }
  51. System.out.println("Operazione svolta con successo.");
  52. }
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement