import java.sql.Connection;
import java.sql.DriverManager;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Properties;
}
@Override
- public String nextValSql(Sequence seq)
+ public long nextVal(Connection con, Sequence seq) throws SQLException
{
- return " SELECT NEXTVAL('" + seq.getName() + "') ";
+ String sql = " SELECT NEXTVAL('" + seq.getName() + "') ";
+
+ try (PreparedStatement ps = con.prepareStatement(sql))
+ {
+ try (ResultSet rs = ps.executeQuery()) {
+ if (rs.next()) {
+ return rs.getLong(1);
+ }
+ }
+ }
+
+ throw new SQLException("No value returned for sequence: " + sql);
}
+
@Override
protected String typeName(Type type) {
// Special case: TIMESTAMPTZ stored as INTEGER (milliseconds since the epoch)