开发者

I am not able to read the records with null date field in MySQL using java?

here is the code

private ResultSet rsResult;

 try
            {
               rsResult = DBProcess.statement.executeQuery("SELECT * FROM patients");

            }//end try
开发者_如何学编程            catch (SQLException ex)
            {
                out.println("<I>exception</I><br>");
                Logger.getLogger(cUserLogin.class.getName()).log(Level.SEVERE, null, ex);
            }//end catch

 while (rsResult.next())
                    {
                        BigDecimal bdPatientID = rsResult.getBigDecimal("patient_id");
                        String strFirstname = rsResult.getString("first_name");
                        String strLastname = rsResult.getString("last_name");
                        String strMiddlename = rsResult.getString("middle_name");
                        String strGeneder = rsResult.getString("gender");
                        String strMeritalStatus = rsResult.getString("marital_status");
                        BigDecimal bdPhoneNo = rsResult.getBigDecimal("phone_no");
                        String strAddress = rsResult.getString("address");
                        String strDOB = rsResult.getDate("birth_dt").toString();
                        String strDOE = rsResult.getDate("dt_of_exam").toString();
                    }

i am not able to read records that are present after a recode which holds the null DATE field what can i do to get raid of this....


If rsResult.getDate("birth_dt") returns null, than calling toString() would cause a NullPointerException

You could rewrite this as:

String strDOB = rsResult.getDate("birth_dt") == null ? "" : rsResult.getDate("birth_dt").toString();
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜