sqlg3.runtime.specific.Postgres Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of sqlg3-runtime Show documentation
Show all versions of sqlg3-runtime Show documentation
SQLG is a preprocessor and a library that uses code generation to simplify writing JDBC code
package sqlg3.runtime.specific;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
/**
* {@link sqlg3.runtime.DBSpecific} implementation for PostgreSQL.
*/
public final class Postgres extends Generic {
public static String getNextSeqSql(String sequence) {
return "SELECT NEXTVAL('" + sequence + "')";
}
@Override
public long getNextId(Connection conn, String sequence) throws SQLException {
try (PreparedStatement stmt = conn.prepareStatement(getNextSeqSql(sequence));
ResultSet rs = stmt.executeQuery()) {
rs.next();
return rs.getLong(1);
}
}
}