Java Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesJava Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Get inside! Sample the range of functionality easily built with JMSL Library for Time Series Data Analysis, Heat Maps, Portfolio Optimization, Monte Carlo Simulation, Stock Price Charting and more. Download Now!
  #1  
Old February 10th, 2001, 10:07 AM
carolchua carolchua is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2001
Location: Singapore
Posts: 0 carolchua User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Question

I've been trying different ways to access the data retrieved but it keeps showing null. Is there something wrong with my codes? Do I need another method? How do I fit these retrieved data into a form (used to collect these data)?

Thanks in advance.

---------------------------------------(truncated codes)
public class UpdatePageServlet extends HttpServlet
{
String userName, filename, layout, backgdColor;...

public void init(ServletConfig config) throws ServletException{...}//init

public void doPost( HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException{
userName = req.getParameter("userName");
filename = req.getParameter("filename");

PrintWriter output = res.getWriter();
res.setContentType("text/html");

//check whether page is created via our template
boolean validPage = checkPage(userName, filename);
//if yes,
if(validPage){output.println(layout);}
//if page created elsewhere
else{ //display error msg
output.println("You have chosen an invalid file format to update. Please select again.");}
}

private boolean checkPage(String aUserName, String aFilename){
try{
String queryUserPage = "SELECT * FROM userPages WHERE userName = '" + aUserName +
"' AND filename = '" + aFilename + "'";
stmt = con.createStatement();
ResultSet rs5 = stmt.executeQuery(queryUserPage);
while (rs5.next()){ //file found
layout = rs5.getString("layout");}
return true;
}
catch (SQLException sqlex){sqlex.printStackTrace();}
return false;
}//checkPage()
}//UpdatePageServlet

[Edited by carolchua on 02-10-2001 at 09:18 AM]

Reply With Quote
  #2  
Old February 12th, 2001, 01:44 PM
wolfespawn wolfespawn is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2001
Posts: 68 wolfespawn User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 8
Send a message via AIM to wolfespawn
When you plug the data items into your query, why are you putting an "a" in front of them? They should be typed exactly as you named the variable. I am also unsure of your question about putting them into a form. You can display them any way you want from this servlet if you threw in the html tags and some get requests. Let me know more specifics... Thanks



Quote:
Originally posted by carolchua
I've been trying different ways to access the data retrieved but it keeps showing null. Is there something wrong with my codes? Do I need another method? How do I fit these retrieved data into a form (used to collect these data)?

Thanks in advance.

---------------------------------------(truncated codes)
public class UpdatePageServlet extends HttpServlet
{
String userName, filename, layout, backgdColor;...

public void init(ServletConfig config) throws ServletException{...}//init

public void doPost( HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException{
userName = req.getParameter("userName");
filename = req.getParameter("filename");

PrintWriter output = res.getWriter();
res.setContentType("text/html");

//check whether page is created via our template
boolean validPage = checkPage(userName, filename);
//if yes,
if(validPage){output.println(layout);}
//if page created elsewhere
else{ //display error msg
output.println("You have chosen an invalid file format to update. Please select again.");}
}

private boolean checkPage(String aUserName, String aFilename){
try{
String queryUserPage = "SELECT * FROM userPages WHERE userName = '" + aUserName +
"' AND filename = '" + aFilename + "'";
stmt = con.createStatement();
ResultSet rs5 = stmt.executeQuery(queryUserPage);
while (rs5.next()){ //file found
layout = rs5.getString("layout");}
return true;
}
catch (SQLException sqlex){sqlex.printStackTrace();}
return false;
}//checkPage()
}//UpdatePageServlet

[Edited by carolchua on 02-10-2001 at 09:18 AM]

Reply With Quote
  #3  
Old February 13th, 2001, 09:24 AM
carolchua carolchua is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2001
Location: Singapore
Posts: 0 carolchua User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Cool

I m actually using another method to do the query so that my doPost is easier to read. In my doPost, I call that method and pass the values in. So the aUserName and userName are actually different. I did the same for my other servlets and they are working fine but not this...

I had a form (in html + jsp) which collected these data and had them stored in the DB. Now I want to retrieve the data and put them in the form for the user to update. Hence this servlet is created. But I can't figure out how to do it....

Reply With Quote
  #4  
Old February 13th, 2001, 10:54 AM
wolfespawn wolfespawn is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2001
Posts: 68 wolfespawn User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 8
Send a message via AIM to wolfespawn
Quote:
Originally posted by carolchua
I m actually using another method to do the query so that my doPost is easier to read. In my doPost, I call that method and pass the values in. So the aUserName and userName are actually different. I did the same for my other servlets and they are working fine but not this...

I had a form (in html + jsp) which collected these data and had them stored in the DB. Now I want to retrieve the data and put them in the form for the user to update. Hence this servlet is created. But I can't figure out how to do it....



_____

Maybe try doing an out.println or System.out on your variables to try and get them to print out so you know that they are at least getting to your servlet. I apologize for previous post, I did not see that you had declared them here

private boolean checkPage(String aUserName, String aFilename){

I only saw the 2 above and didn't realize the spelling difference.
I have a question for you, I have never seen the double and single quotes used in a query statement like you use. I have only used doubles. Do you do that in all your queries? the "'+ aUserName +'" ..... ??

Do you have error logs so you can see your query running in background??

Reply With Quote
  #5  
Old February 14th, 2001, 09:25 AM
carolchua carolchua is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2001
Location: Singapore
Posts: 0 carolchua User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Smile

I'll play with my codes again after my exam. Hopefully someone can enlighten me in the meantime...

The single quotes is for the SQL statement while in servlets. " can't be used so ' is used instead.

Didn't cater for logs, usually exceptions will "tell" me that my coding is wrong.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesJava Help > help! How to access the data retrieved & put into forms?


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway