Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package ua.dex.data;
- import java.sql.*;
- /**
- * Created by dexter on 07.01.17.
- */
- public class Data {
- public static void main(String[] args) {
- System.out.println("Loading driver...");
- try {
- Class.forName("com.mysql.jdbc.Driver").newInstance();
- System.out.println("Driver loaded!");
- } catch (ClassNotFoundException e) {
- throw new IllegalStateException("Cannot find the driver in the classpath!", e);
- } catch (IllegalAccessException e) {
- e.printStackTrace();
- } catch (InstantiationException e) {
- e.printStackTrace();
- }
- String url = "jdbc:mysql://localhost:3306/dexchat";
- String username = "root";
- String password = "root";
- System.out.println("Connecting database...");
- try (Connection connection = DriverManager.getConnection(url, username, password)) {
- System.out.println("Database connected!");
- PreparedStatement statement = connection.prepareStatement("SELECT * FROM clients");
- ResultSet rs = statement.executeQuery();
- System.out.println("All clients");
- while (rs.next()){
- System.out.println("id : " + rs.getInt("id"));
- System.out.println("email : " + rs.getString("email"));
- System.out.println("login : " + rs.getString("login"));
- System.out.println("name : " + rs.getString("name"));
- System.out.println("pass : " + rs.getString("pass"));
- }
- } catch (SQLException e) {
- throw new IllegalStateException("Cannot connect the database!", e);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement