URGENT return value problem.....from java function.
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Lijo_John
Posted On:   Friday, December 21, 2001 10:59 PM

My question is that suppose we have a function is java which accepts a string value. and that string value is passed to ResultSet to query a table. i just want to check that a record is present or not,in the database, with the key value which ispassed to the function. this function is having a return type as string. now the problem is if the item is found in the data base then its ok but if it is not there then now to check ...like... public String check(String s) { PreparedStatement pstmt = conn.prepareStatement("select * from ptest where y = ?"); pstmt.setString(1,s)//the passed string while(rs.next()) { //database interaction... String nam   More>>

My question is that suppose we have a function is java which accepts a string value. and that string value is passed to ResultSet to query a table. i just want to check that a record is present or not,in the database, with the key value which ispassed to the function. this function is having a return type as string. now the problem is if the item is found in the data base then its ok but if it is not there then now to check ...like...



public String check(String s)
{

PreparedStatement pstmt = conn.prepareStatement("select * from ptest where y = ?");

pstmt.setString(1,s)//the passed string


while(rs.next())

{

//database interaction...

String name = rs.getString(1);

}


return name;

}


now suppose the query in oracle does not fine anything then there will be null in variable "name".

then can we check likethis...

if(name == null)

{

//some statements

}

else

{



}


i mean how to put the return value in a condition. becaue i tried .equals but that is not working.


thank u ...



bhargav..

   <<Less

Re: URGENT return value problem.....from java function.

Posted By:   Bernie_Acs  
Posted On:   Saturday, December 22, 2001 05:59 AM



JDBC Answer

ResultSet.wasNull()

public boolean wasNull()
throws SQLException


Reports whether
the last column read had a value of SQL NULL.
Note that you must first call one of the getXXX methods
on a column to try to read its value and then call
the method wasNull to see if the value read was
SQL NULL.

Returns:
true if the last column value read was SQL
NULL and false otherwise
Throws:
SQLException - if a database access error occurs







OR


SQL Answer


With Oracle the NVL() can be used to return a suppied value when the selected value is null as follows


Select nvl(Name, 'NULL_FOUND')
from ptest where y = ?
About | Sitemap | Contact