Guest User

Untitled

a guest
Mar 14th, 2018
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.09 KB | None | 0 0
  1. Statement stmt = null;
  2. ResultSet rs = null;
  3.  
  4. Connection conn = null;
  5. try {
  6. conn =
  7. DriverManager.getConnection("jdbc:mysql://localhost/mydb?" +
  8. "user=root&password=glight28");
  9. System.out.println("Connected! oh yeah");
  10. //creare Statement che serve a fare le query
  11. stmt = conn.createStatement();
  12. //esecuzione query che -> salva risultato in rs che รจ un ResultSet
  13. rs = stmt.executeQuery("SELECT * FROM students");
  14.  
  15. if (rs != null) {
  16. while (rs.next()) {
  17. System.out.println(rs.getString("Name"));
  18. }
  19.  
  20. }
  21. } catch (SQLException ex) {
  22. // catturare errori
  23. System.out.println("SQLException: " + ex.getMessage());
  24. System.out.println("SQLState: " + ex.getSQLState());
  25. System.out.println("VendorError: " + ex.getErrorCode());
  26. }finally {
  27. rs = null;
  28. }
Add Comment
Please, Sign In to add comment