• Post Reply Bookmark Topic Watch Topic
  • New Topic

String Tokenizer in JSP

 
prathimaprasun rao
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello everyone,
I can insert reocrds into the table. When I try to retrieve the data using the Select statement into the edit screen, I could populate all the data from the database into the corresponding fields except the phone and fax.
I have written the following code:

if (mode.equals("edit")) {

userID = request.getParameter("userID");

strSQL = "SELECT user_id, last_name, first_name, middle_name, department, location, title, email, "+
" phone, phone_ext, fax, account_status_flag, round(date_password_reset - sysdate) accountExpired "+
" FROM dss_user WHERE user_id = '" + userID +"'";
//out.println(strSQL);
db.setSQL(strSQL) ;
db.query() ;
db.getNextRow() ;

lastName = db.getData("last_name") ;
firstName = db.getData("first_name") ;
mName = db.getData("middle_name") ;
DCName = db.getData("department") ;
location = db.getData("location") ;
title = db.getData("title") ;
email = db.getData("email") ;
phone = db.getData("phone") ;
phoneExt = db.getData("phone_ext") ;
fax = db.getData("fax") ;
accountStatus = db.getData("account_status_flag") ;
accountExpired = db.getData("accountExpired") ;

strSQL = "SELECT role_nmbr FROM dss_user_role WHERE user_id='"+ userID+"'";
//out.println(strSQL);
db.setSQL(strSQL) ;
db.query() ;
db.getNextRow() ;
profileAssigned = db.getData("role_nmbr") ;

//out.println("phone "+ phone + "fax "+ fax);
if (!phone.equals("")) {
StringTokenizer t = new StringTokenizer(phone, "-");

pAreaCode = t.nextToken();
subPhone = t.nextToken();
mainPhone = t.nextToken();
}

if (!fax.equals("")) {
StringTokenizer t2 = new StringTokenizer(fax, "-");

while (t2.hasMoreTokens()) {
fAreaCode = t2.nextToken();
subFax = t2.nextToken();
mainFax = t2.nextToken();
}

}

} //end if mode = edit


Could anyone provide me the solution to the problem.
Waiting for reply!
Prathima
 
Gaurav Chikara
Ranch Hand
Posts: 413
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It seems your stringtokenizer is not created properly
I am sure the delimiter you are using and delimitor database is returning are not matching
Please put a break point on the place where you construct String tokenizer and inspect hasMoreTokens method
That should give you the reason
 
prathimaprasun rao
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hello gaurav,
could you provide solution to the code provided?

Waiting for reply!
Prathima
 
prathimaprasun rao
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hello gaurav,
i just declared two variables "pdelim, fdelim" and initialized with "-";

Will the following code solve my problem?


String strSQL = "";
String mode = "";
String dhr_id = "";

String userID = "";
String userPassword = "";
String lastName= "";
String firstName = "";
String mName = "";
String DCName = "";
String location = "";
String title = "";
String email= "";
String pAreaCode = "";
String subPhone = "";
String mainPhone = "";
String phoneExt = "";
String fAreaCode = "";
String subFax = "";
String mainFax = "";
String accountStatus = "";
String profileAssigned = "Staff Users";
String accountExpired= "";
String phone = "";
String fax = "";
String pdelim= "-";
String fdelim = "-";


Vector UserRolesVector = new Vector();
String strSelected1 = "",strSelected2 = "",strSelected3 = "", strSelected4 = "";

Connection conn = null ;
conn = pool.getConnection() ;
dss.Database db = new dss.Database( conn ) ;

try {
mode = request.getParameter("mode");

//look up UserRoles List
strSQL = "select role_nmbr value, role_name display from dss_role order by 2";
//out.println(strSQL);
db.setSQL(strSQL) ;
db.query() ;
UserRolesVector = db.getSelectionList() ;

// ******** Doing Edit ****************
if (mode.equals("edit")) {

userID = request.getParameter("userID");

strSQL = "SELECT user_id, last_name, first_name, middle_name, department, location, title, email, "+
" phone, phone_ext, fax, account_status_flag, round(date_password_reset - sysdate) accountExpired "+
" FROM dss_user WHERE user_id = '" + userID +"'";
//out.println(strSQL);
db.setSQL(strSQL) ;
db.query() ;
db.getNextRow() ;

lastName = db.getData("last_name") ;
firstName = db.getData("first_name") ;
mName = db.getData("middle_name") ;
DCName = db.getData("department") ;
location = db.getData("location") ;
title = db.getData("title") ;
email = db.getData("email") ;
phone = db.getData("phone") ;
phoneExt = db.getData("phone_ext") ;
fax = db.getData("fax") ;
accountStatus = db.getData("account_status_flag") ;
accountExpired = db.getData("accountExpired") ;

strSQL = "SELECT role_nmbr FROM dss_user_role WHERE user_id='"+ userID+"'";
//out.println(strSQL);
db.setSQL(strSQL) ;
db.query() ;
db.getNextRow() ;
profileAssigned = db.getData("role_nmbr") ;

//out.println("phone "+ phone + "fax "+ fax);
if (!phone.equals("")) {
StringTokenizer t = new StringTokenizer(phone, pdelim);
while (t.hasMoreTokens()) {
pAreaCode = t.nextToken();
subPhone = t.nextToken();
mainPhone = t.nextToken();
}

if (!fax.equals("")) {
StringTokenizer t2 = new StringTokenizer(fax, fdelim);

while (t2.hasMoreTokens()) {
fAreaCode = t2.nextToken();
subFax = t2.nextToken();
mainFax = t2.nextToken();
}

}

} //end if mode = edit


} //end try
catch(NoSuchElementException e) {
//out.println(e.getMessage());
}
catch ( Exception e) {
out.println ( e.toString() ) ;
} finally {
db.cleanup() ;
}


Waiting for reply!
Prathima
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As Gaurav Chikara says, the problem looks like your StringTokenizer. Add some debug logging to check you have a value for "phone" and it is delimited as you expect it to be.
 
What are you doing? You are supposed to be reading this tiny ad!
the new thread boost feature brings a LOT of attention to your favorite threads
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!