Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to find null (ResultSet + PreparedStatement))

 
Tushar Kherde
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
following method i am calling recursively. craeting a dyanamic menu on basis of userid and application code so i am finding the childs of child and so on ......... Connection object is global here. Rest all the thing are local.


Problem is program flow is not going into if(matrixResultSet==null)

can anybody help me out.

i tried sql query on sql promt it showing null. what could be the problem







ResultSet matrixResultSet=null;
PreparedStatement matrixPreparedStatement=null;

if(userId != null && appCode != null && userId.trim().length() > 0 && appCode.trim().length() > 0){
matrixPreparedStatement = (PreparedStatement)con.prepareStatement( " Select * from ICE_MODULE_MENU where APP_CODE=? AND MOD_PARENT_MENU=?");
}

matrixPreparedStatement.setString(1, appCode);
matrixPreparedStatement.setString(2, moduleCode);
matrixPreparedStatement.executeQuery();
matrixResultSet = matrixPreparedStatement.getResultSet();

if(matrixResultSet==null){

//Flow is not coming here

menuString.append(",");

}


while (matrixResultSet.next()){
String parentModuleName = matrixResultSet.getString("MOD_CODE");

logger.debug("this.renderURL"+this.renderURL);

menuString.append("[null,'Home','"+this.renderURL+"/index.jsp',null,null,");

logger.debug(parentModuleName);
this.makeMenu(parentModuleName, appCode, userId, con);

menuString.append("] ");

}
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The ResultSet will never be null. It may be empty, but never null.
 
Tushar Kherde
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Paul,

but my problem is how to find that the resultset is empty.
is there any method
 
Dag Corell
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The first call to matrixResultSet.next() would return false.

Code something like this..
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic