wood burning stoves 2.0*
The moose likes JDBC and the fly likes String Tokenizer in JSP Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "String Tokenizer in JSP" Watch "String Tokenizer in JSP" New topic
Author

String Tokenizer in JSP

prathimaprasun rao
Ranch Hand

Joined: Jun 29, 2006
Posts: 55
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

Joined: Jun 09, 2000
Posts: 410
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


SCJP,SCWCD,SCBCD<br />If Opportunity doesn't knock then build the door
prathimaprasun rao
Ranch Hand

Joined: Jun 29, 2006
Posts: 55
hello gaurav,
could you provide solution to the code provided?

Waiting for reply!
Prathima
prathimaprasun rao
Ranch Hand

Joined: Jun 29, 2006
Posts: 55
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

Joined: Apr 14, 2004
Posts: 10336

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.


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
 
 
subject: String Tokenizer in JSP
 
Similar Threads
problem retrieving from database
update problem in oracle
msyql jdbc problem.
Hibernate: adding underscore to attibute names
query problem