Advertisement
Guest User

Untitled

a guest
Feb 3rd, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.78 KB | None | 0 0
  1. import java.sql.*;
  2.  
  3. public class PrimoJDBC {
  4.  
  5. public static void main(String[] args) {
  6.  
  7. Connection conn= null;
  8. try
  9. {
  10. Class.forName("com.mysql.jdbc.Driver");
  11. String url="jdbc:mysql://127.0.0.1:3306/?user=root";
  12. String username="root";
  13. String password="giovanni";
  14. conn=DriverManager.getConnection(url, username, password);
  15. }catch(Exception e){
  16. System.out.println("connessione fallita.");
  17.  
  18. }
  19. try
  20. {
  21.  
  22. Statement query=conn.createStatement();
  23. ResultSet risultato=query.executeQuery("select * from Libro");
  24. while(risultato.next()) {
  25. String isbn= risultato.getString("isbn");
  26. System.out.println(isbn);
  27. }
  28.  
  29. }
  30. catch(Exception e)
  31. {
  32. System.out.println("errore nell'interrogazione.");
  33. }
  34. }
  35.  
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement