Converting MySQL result array to JSON [duplicate]
json_encode is available in php > 5.2.0: echojson_encode($row);
json_encode is available in php > 5.2.0: echojson_encode($row);
Personally I’d use a pool as this will take care of all of the resource management for you. If your connection requirements change then you can easily modify the pool configuration. With a pool in place you can open/close connections and prepared statements according to best-practice and leave the resource management to the pool. Typically, … Read more
The problem is with the way you fetch data in getStuff(). Each time you visit getStuff() you obtain a fresh ResultSet but you don’t close it. This violates the expectation of the Statement class (see here – http://docs.oracle.com/javase/7/docs/api/java/sql/Statement.html): By default, only one ResultSet object per Statement object can be open at the same time. Therefore, … Read more
You will notice while researching the PHP manual at https://php.net/manual/en/mysqli-result.fetch-array.php that fetch_array() has the default behavior of generating a result set that contains both indexed and associative keyed elements (MYSQLI_BOTH). You could use either MYSQLI_ASSOC … while ($row = $output->fetch_array(MYSQLI_ASSOC)) { echo $row[‘uid’]; } or MYSQLI_NUM… while ($row = $output->fetch_array(MYSQLI_NUM)) { echo $row[0]; } That … Read more
Most database vendors don’t support JDBC 4.2 yet. This specification says that the new java.time-types like LocalDate will/should be supported using the existing methods setObject(…) and getObject(). No explicit conversion is required and offered (no API-change). A workaround for the missing support can be manual conversion as described on the Derby-mailing list. Something like: LocalDate … Read more
You might try removing the BufferedWriter and just using the FileWriter directly. On a modern system there’s a good chance you’re just writing to the drive’s cache memory anyway. It takes me in the range of 4-5 seconds to write 175MB (4 million strings) — this is on a dual-core 2.4GHz Dell running Windows XP … Read more
Do a SELECT COUNT(*) FROM … query instead. OR int size =0; if (rs != null) { rs.last(); // moves cursor to the last row size = rs.getRow(); // get row id } In either of the case, you won’t have to loop over the entire data.
SELECT * FROM T1 WHERE id IN (1,2);