Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.sql.*;
- public class App {
- private Connection c;
- public App() {
- try {
- Class.forName("org.postgresql.Driver");
- System.out.println("carregou");
- } catch (ClassNotFoundException ex) {
- ex.printStackTrace();
- }
- }
- public void setConnection() throws SQLException {
- String host = "https://database-1.cceebyyef1n1.us-east-1.rds.amazonaws.com/";
- String db = "bd_aula";
- String url = "jdbc:postgresql://" + host + "/" + db;
- String user = "aluno";
- String senha = "aluno";
- c = DriverManager.getConnection(url, user, senha);
- }
- public void executarConsulta() throws SQLException {
- Statement st = c.createStatement();
- String sql = "SELECT * FROM universidade.professor";
- ResultSet rs = st.executeQuery(sql);
- while (rs.next()) {
- System.out.println(rs.getRow() + " ");
- String col1 = rs.getString(1);
- String col2 = rs.getString(2);
- String data = rs.getString("data_nascimento");
- System.out.println(col1 + "\t" + col2 + "\t" + data);
- }
- }
- public static void main(String[] args) {
- App t = new App();
- try {
- t.setConnection();
- System.out.println("conexão ok...");
- t.executarConsulta();
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement