Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package lib;
- import java.sql.Connection;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- import java.sql.Statement;
- import org.postgresql.ds.PGSimpleDataSource;
- public class Databazy {
- public static void main(String[] args) throws SQLException {
- PGSimpleDataSource dataSource = new PGSimpleDataSource();
- dataSource.setServerName("db.dai.fmph.uniba.sk");
- dataSource.setPortNumber(5432);
- dataSource.setDatabaseName("playground");
- dataSource.setUser("mizerik1@uniba.sk");
- dataSource.setPassword("jozko123");
- try(Connection con = dataSource.getConnection()) {
- try(Statement s = con.createStatement()) {
- //s.executeQuery("SELECT import_company()");
- try(ResultSet r = s.executeQuery("select employee_id, first_name, last_name from employees")){
- while(r.next()) {
- int employeeId = r.getInt(1);
- String firstName = r.getString(2);
- String lastName = r.getString(3);
- System.out.println(employeeId + " " + firstName + " " + lastName);
- }
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement