package teste;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class TesteBancoDados {
	
	private static final String URL = "jdbc:postgresql://localhost:5432/postgres"; 
	
	public void acessar() throws SQLException {
		DriverManager.registerDriver(new org.postgresql.Driver());
		Connection conn = DriverManager.getConnection(TesteBancoDados.URL, "postgres", "aluno");
		Statement stmt = conn.createStatement();
		ResultSet rSet = stmt.executeQuery("SELECT * FROM SERVIDOR_BASICO");
		while(rSet.next()) {
			System.out.println(rSet.getString("id"));
		}
		rSet.close();
		stmt.close();
		conn.close();
		System.out.println("FIM");
	}
	
	public void inserir() throws SQLException {
		
		String insert = "INSERT INTO SERVIDOR_BASICO " + 
		                "(id, latenciaLeitura, latenciaEscrita, " +
		                 "capacidadeOcupada, capacidadeTotal )  " +
		                "VALUES('bastet', 0.15, 0.30, 0, 1024)";
		
		DriverManager.registerDriver(new org.postgresql.Driver());
		Connection conn = DriverManager.getConnection(TesteBancoDados.URL, "postgres", "aluno");
		Statement stmt = conn.createStatement();
		stmt.executeUpdate(insert);
		stmt.close();
		conn.close();
		System.out.println("FIM");
	}
	
	
	public static void main(String[] args) throws SQLException {
		(new TesteBancoDados()).acessar();
	}

}
