Skip to content

Instantly share code, notes, and snippets.

@efenderbosch
Last active February 16, 2016 20:34
Show Gist options
  • Save efenderbosch/6469255 to your computer and use it in GitHub Desktop.
Save efenderbosch/6469255 to your computer and use it in GitHub Desktop.
simple JDBC
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();
}
}
<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