Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.IOException;
- import java.sql.*;
- public class Solution {
- public static void main(String[] args) throws ClassNotFoundException, SQLException, IOException {
- DriverManager.registerDriver(new com.mysql.jdbc.Driver());
- String url = "jdbc:mysql://localhost";
- Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
- Connection con = DriverManager.getConnection(url, "root@localhost", "cleverforever");
- Statement stmt = con.createStatement();
- stmt.executeQuery("USE university");
- ResultSet rs = stmt.executeQuery("SElECT surname, name, secondName, birth, id FROM students");
- dispResultSet(rs);
- stmt.close();
- }
- private static void dispResultSet(ResultSet rs) throws SQLException, IOException {
- while (rs.next()) {
- System.out.print(rs.getString("surname") + " ");
- System.out.print(rs.getString("name") + " ");
- System.out.print(rs.getString("secondName") + " ");
- System.out.print(rs.getDate("birth") + " ");
- System.out.print(rs.getInt("id"));
- System.out.println();
- }
- }
- }
Add Comment
Please, Sign In to add comment