ResultSet: Retrieving column values by index versus retrieving by label

Warning: I’m going to get bombastic here, because this drives me crazy. 99%* of the time, it’s a ridiculous micro-optimization that people have some vague idea makes things ‘better’. This completely ignores the fact that, unless you’re in an extremely tight and busy loop over millions of SQL results all the time, which is hopefully … Read more

Execute anonymous pl/sql block and get resultset in java

Here is a self contained example of how to “execute the anonymous PL/SQL and get the resultset object” import java.sql.CallableStatement; import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.Types; import oracle.jdbc.OracleTypes; public class CallPLSQLBlockWithOneInputStringAndOneOutputStringParameterAndOneOutputCursorParameter { public static void main(String[] args) throws Exception { DriverManager.registerDriver(new oracle.jdbc.OracleDriver()); // Warning: this is a simple example program : In a … Read more

JDBC driver throws “ResultSet Closed” exception on empty ResultSet

Empty or not, but doing the following is always faulty: resultSet = statement.executeQuery(sql); string = resultSet.getString(1); // Epic fail. The cursor isn’t set yet. This is not a bug. This is documented behaviour. Every decent JDBC tutorial mentions it. You need to set the ResultSet’s cursor using next() before being able to access any data. … Read more

How do you implement pagination in PHP? [closed]

You’ll need a beginner’s understanding of PHP, and probably some understanding of relational databases. Pagination is often implemented with some simple query parameters. stackoverflow.com/myResults.php?page=1 The page increments the query parameter: stackoverflow.com/myResults.php?page=2 On the back end, the page value usually corresponds to the limits and offsets in the query that is being used to generate the … Read more

Retrieving Multiple Result sets with stored procedure in php/mysqli

I think you’re missing something here. This is how you can get multiple results from stored procedure using mysqli prepared statements: $stmt = mysqli_prepare($db, ‘CALL multiples(?, ?)’); mysqli_stmt_bind_param($stmt, ‘ii’, $param1, $param2); mysqli_stmt_execute($stmt); // fetch the first result set $result1 = mysqli_stmt_get_result($stmt); // you have to read the result set here while ($row = $result1->fetch_assoc()) { … Read more