Created
November 29, 2022 02:12
-
-
Save andrewdoss-bit/08d86fe454418ea74e97c77b91f40c56 to your computer and use it in GitHub Desktop.
bit.io JDBC connection test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.sql.*; | |
import java.util.Properties; | |
public class Query { | |
// Note that the 'username/db_name' must use a '.' instead of a '/' for JDBC | |
private static final String url = | |
"jdbc:postgresql://db.bit.io/dliden.2020_Census_Reapportionment"; | |
public static void main(String[] args) { | |
Properties props = new Properties(); | |
props.setProperty("sslmode", "require"); | |
props.setProperty("user", "doss"); | |
props.setProperty("password", "<redacted>"); | |
Connection conn = null; | |
try { | |
conn = DriverManager.getConnection(url, props); | |
} catch (SQLException e) { | |
System.out.println(e.getMessage()); | |
} | |
try { | |
Statement st = conn.createStatement(); | |
ResultSet rs = st.executeQuery( | |
"SELECT COUNT(*) FROM \"dliden/2020_Census_Reapportionment\".\"Historical Apportionment\" WHERE \"Name\" ='Alabama';" | |
); | |
rs.next(); | |
System.out.println(rs.getInt(1)); | |
rs.close(); | |
st.close(); | |
} catch (SQLException e) { | |
System.out.println(e.getMessage()); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment