Advertisement
Guest User

Untitled

a guest
Jun 26th, 2017
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.12 KB | None | 0 0
  1. package wbs.jdbc;
  2.  
  3.  
  4. import java.sql.Connection;
  5. import java.sql.DriverManager;
  6. import java.sql.SQLException;
  7. import java.sql.ResultSet;
  8. import java.sql.Statement;
  9.  
  10. public class ResultSetDemo {
  11. public static void main(String[] args) {
  12. String url = "jdbc:mysql://sql513.your-server.de/wbs_db1?useUnicode=yes&characterEncoding=UTF-8&useSSL=false";
  13. String user = "wbsdatenbank";
  14. String password = "Wbsdatenbank1";
  15. String sql = "SELECT * FROM buch";
  16.  
  17. String isbn;
  18. String autor;
  19. String titel;
  20. double preis;
  21.  
  22. try (Connection connection = DriverManager.getConnection(url, user, password);
  23. Statement statement = connection.createStatement();
  24. ResultSet rs = statement.executeQuery(sql)) {
  25. while (rs.next()) {
  26. isbn = rs.getString("isbn");
  27. autor = rs.getString("autor");
  28. titel = rs.getString("titel");
  29. preis = rs.getDouble("preis");
  30.  
  31. //System.out.println(resultSet.getInt("id") + " -> " + resultSet.getString("data"));
  32. System.out.printf("%-20s%-30s%-40s%8.2f%n", isbn, autor, titel, preis);
  33. }
  34. } catch (SQLException sqle) {
  35. sqle.printStackTrace();
  36. }
  37. }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement