Guest User

Untitled

a guest
May 11th, 2018
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.14 KB | None | 0 0
  1. import java.io.IOException;
  2. import java.sql.*;
  3.  
  4. public class Solution {
  5.  
  6. public static void main(String[] args) throws ClassNotFoundException, SQLException, IOException {
  7. DriverManager.registerDriver(new com.mysql.jdbc.Driver());
  8. String url = "jdbc:mysql://localhost";
  9. Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
  10. Connection con = DriverManager.getConnection(url, "root@localhost", "cleverforever");
  11. Statement stmt = con.createStatement();
  12. stmt.executeQuery("USE university");
  13. ResultSet rs = stmt.executeQuery("SElECT surname, name, secondName, birth, id FROM students");
  14. dispResultSet(rs);
  15. stmt.close();
  16. }
  17.  
  18. private static void dispResultSet(ResultSet rs) throws SQLException, IOException {
  19. while (rs.next()) {
  20. System.out.print(rs.getString("surname") + " ");
  21. System.out.print(rs.getString("name") + " ");
  22. System.out.print(rs.getString("secondName") + " ");
  23. System.out.print(rs.getDate("birth") + " ");
  24. System.out.print(rs.getInt("id"));
  25. System.out.println();
  26. }
  27. }
  28. }
Add Comment
Please, Sign In to add comment