Skip to content

Instantly share code, notes, and snippets.

Created July 17, 2020 18:00
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
import java.sql.*;
import java.util.*;
class Main {
public static void main(String[] args) {
try {
// Connections
String url = "jdbc:postgresql://";
Properties props = new Properties();
Connection conn = DriverManager.getConnection(url, props);
// get these from args passed into the function
// id or uuid is the ID for row to UPDATE
// timestamp type will update the column accordingly
int id = 1;
String timestampType = "start"; // or "end". Refers to DB columns
// Get the exact time in milliseconds
long startTime = System.currentTimeMillis() / 1000L;
String startTimeString = String.valueOf(startTime);
// Prepare SQL statement with variables
PreparedStatement st = conn.prepareStatement("UPDATE streams SET " +
timestampType +
" = ? WHERE id = ?");
st.setString(1, startTimeString);
st.setInt(2, id);
// Log statement before running
System.out.println("=====EXECUTING QUERY=======");
// execute
ResultSet rs = st.executeQuery();
// Add loop over results here if needed.
// close
} catch (Exception e) {
System.out.println("Whoops world!" + e);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment