Board index » jbuilder » how to test for null return from Oracle database

how to test for null return from Oracle database


2005-02-18 02:52:38 AM
jbuilder2
Hi There,
How can I test for null return from Oracle database and display an error
message to the user?
Basically, I wan to display an error message to the user if the query return
is null.
Here's an event button code...
void jButton1_actionPerformed(ActionEvent e) {
try {
parameterRow1.setString("STAID", jTextField1.getText());
queryDataSet1.executeQuery();
queryDataSet2.executeQuery();
if ((jTextField1.getText()) == null)
{
JOptionPane.showMessageDialog(this,"Please enter a Station ID!");
}
if (queryDataSet1.getRowCount() < 1)
JOptionPane.showMessageDialog(this,"Station ID not found!");
}
}
catch (DataSetException ex) {
JOptionPane.showMessageDialog(this, ex);
}
}
Thanks,
Tom
 
 

Re:how to test for null return from Oracle database

Tom wrote:
I'm a little confused by your question and the description
you give below.
What does "return null" mean to you in the following scenario?
Quote
How can I test for null return from Oracle database and display an error
message to the user?
Basically, I want to display an error message to the user if the query return
is null.

Here's an event button code...

void jButton1_actionPerformed(ActionEvent e) {

try {
parameterRow1.setString("STAID", jTextField1.getText());
queryDataSet1.executeQuery();
queryDataSet2.executeQuery();

if ((jTextField1.getText()) == null)
{
JOptionPane.showMessageDialog(this,"Please enter a Station ID!");
}
First, "JTextField.getText()" will return a String of length 0 (zero),
not null. But that has nothing to do with Oracle or queries.
Second, if you have the requirement that the user
enter a "station id", it seems logical that you would
do the check *before* executing the queries.
Third, what does queryDataset2 have anything to do
with anything here?
Quote
if (queryDataSet1.getRowCount() < 1) {
JOptionPane.showMessageDialog(this,"Station ID not found!");
}
Why not test rowCount == 0 instead of less than 1?
queryDataset1 won't be null, so there's no sense in
testing for null here.
Quote
}
catch (DataSetException ex) {
JOptionPane.showMessageDialog(this, ex);
}
}
The question is, what does "return a null" mean in
the above scenario? The query dataset isn't null
assuming that you have instantiated it. If
something goes wrong with executing a query, an
exception may be thrown. It's good that you are
catching that.
You don't try to get anything from any of the rows
of the dataset ... so, are you asking how to handle
something like
querydataset.getString("...")
which might return null? If so, DataSet has a method
for checking whether a column value is null.
--
Paul Furbacher (TeamB)
Save time, search the archives:
www.borland.com/newsgroups/ngsearch.html
Is it in Joi Ellis's Faq-O-Matic?
www.visi.com/~gyles19/fom-serve/cache/1.html
Finally, please send responses to the newsgroup only.
That means, do not send email directly to me.
Thank you.