Last active
February 16, 2016 20:34
-
-
Save efenderbosch/6469255 to your computer and use it in GitHub Desktop.
simple JDBC
This file contains hidden or 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.Connection; | |
import java.sql.DriverManager; | |
import java.sql.ResultSet; | |
import java.sql.SQLException; | |
import java.sql.Statement; | |
import java.sql.Timestamp; | |
public class Test { | |
public static void main(String[] args) throws Exception { | |
Connection conn = DriverManager.getConnection("jdbc:postgresql://hostname:port/schema", "username", "password"); | |
try { | |
doStuff(conn); | |
} finally { | |
conn.close(); | |
} | |
} | |
private static void doStuff(Connection conn) throws SQLException { | |
Statement stmt = conn.createStatement(); | |
ResultSet rs = stmt.executeQuery("select now()"); | |
while (rs.next()) { | |
Timestamp ts = rs.getTimestamp(1); | |
System.out.println(ts); | |
} | |
stmt.close(); | |
} | |
} |
This file contains hidden or 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
<dependency> | |
<groupId>org.postgresql</groupId> | |
<artifactId>postgresql</artifactId> | |
<version>9.2-1003-jdbc4</version> | |
</dependency> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment