Note that there are some explanatory texts on larger screens.

plurals
  1. POReading null values from ResultSet
    primarykey
    data
    text
    <p>There is the following table that may contain empty values for STA, ETA or ATA:</p> <pre><code>CREATE TABLE `flightschedule` ( `id` smallint(6) NOT NULL AUTO_INCREMENT, `flightNum_arr` varchar(40) DEFAULT NULL, `from_ICAO` varchar(20) DEFAULT NULL, `STA` datetime DEFAULT NULL, `ETA` datetime DEFAULT NULL, `ATA` datetime DEFAULT NULL, `pk_arr` varchar(10) DEFAULT NULL PRIMARY KEY (`id`) ) ENGINE=MyISAM AUTO_INCREMENT=5611 DEFAULT CHARSET=latin1; </code></pre> <p>The query is:</p> <blockquote> <p>SELECT flightNum_arr,STA,ETA,ATA,airlineICAO,aircraftType,pk_arr FROM flightschedule";</p> </blockquote> <p>When I try to read data from this table in my Java code, the following error occurs:</p> <blockquote> <p>java.sql.SQLException: Cannot convert value '0000-00-00 00:00:00' from column 2 to TIMESTAMP.</p> </blockquote> <p>It occurs at line <code>record[i] = rs.getString(i + 1);</code></p> <p>I introduced the following checking, but it does not seem to be working:</p> <pre><code>if(record[i] == null) { record[i]= ""; } </code></pre> <p>The code:</p> <pre><code>public void setQuery(String query) { cache = new Vector(); try { // Execute the query and store the result set and its metadata Connection con = getConnection(); Statement statement = con.createStatement(); ResultSet rs = statement.executeQuery(query); ResultSetMetaData meta = rs.getMetaData(); colCount = meta.getColumnCount(); // Rebuild the headers array with the new column names headers = new String[colCount]; for (int h = 1; h &lt;= colCount; h++) { headers[h - 1] = meta.getColumnName(h); } while (rs.next()) { String[] record = new String[colCount]; for (int i = 0; i &lt; colCount; i++) { record[i] = rs.getString(i + 1); if(record[i] == null) { record[i]= ""; } } cache.addElement(record); } fireTableChanged(null); rs.close(); if (con.getAutoCommit() != false) { con.close(); } } catch (Exception e) { cache = new Vector(); // blank it out and keep going. e.printStackTrace(); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload