aspose file tools*
The moose likes JSP and the fly likes Retrive a single data from database and display that in jsp text box. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "Retrive a single data from database and display that in jsp text box." Watch "Retrive a single data from database and display that in jsp text box." New topic
Author

Retrive a single data from database and display that in jsp text box.

P Arunkumar
Ranch Hand

Joined: Jan 05, 2012
Posts: 119
Hi

I tried to retrive the data from database its perfect but iam getting all the datas but my problem is i can't retrive a single data from database and i need to display that data in jsp page.


I tried but i am not getting any error, iam getting my jsp page but after iam giving a data and click the submit button its in blank only i can't retrive them please help me to solve my issue.


My database is MYSql. just two datas if i retrive from database and shown in jsp field mens then i will develop remaing information.

my database code is :


My jsp code is



I know that iam doing mistake but i can't find it in google also i tried iam getting fail only Please Guide me to solve my issue. no one is not there to guide me in my office iam developing alone so please solve my issue as soon as possible and give guide to me.Because by using this idea only iam going develop my project in frameworks is just foundation so please put my foundation strongly.

Thanks in advance.
Gopakumar Naryanan
Ranch Hand

Joined: Jan 15, 2011
Posts: 72

Correct your Query. Are there many records with fname?
I guess you may want to pass the requestParameter 'fname' in your query. Please check it.


Thanks & Regards
Gopakumar
P Arunkumar
Ranch Hand

Joined: Jan 05, 2012
Posts: 119
Hi


I have changed my code but still its same only, if i give my fname it wants to show my first name and last name from database in database also i am having same fname and lname only.

Gopakumar Naryanan
Ranch Hand

Joined: Jan 15, 2011
Posts: 72



try this.
P Arunkumar
Ranch Hand

Joined: Jan 05, 2012
Posts: 119
I have tried but still ame issue. now iam give my full sapmle code its for sample only later i will make it with servlet code, my code in jsp page in jsp page java code its not perfect i know but for time being iam using like this don't mistake me.

my jsp page.



Please solve me.
Gopakumar Naryanan
Ranch Hand

Joined: Jan 15, 2011
Posts: 72

:confused: Forget about all these things.. make it clear what are you trying to do?

As far as i understood, you are taking fname from the user and trying to retrieve data related to the 'fname'(of one perticular user). you are getting multiple records instead of one.

am i right?

please display the value of the 'fname' variable... use SQLException and ClassNotFoundException classes in catch block.

Please Write the servlet code in java file.. i'm not used of these scriptlets etc. :thumbdown:

Make it more clear.. it will be easy to solve the problem.

P Arunkumar
Ranch Hand

Joined: Jan 05, 2012
Posts: 119
Hi

I have tried But iam getting error Exception is : Java.SQL.SQLException: After end of result set.

My Jsp Page : find.jsp



WelcomeServlet


Web.xml:



I am having some username and password in my database if i gave username and click ok means it wants to show the password in the text box.
It is like find option. please help me to solve my issue.


Thanks in advance.
P Arunkumar
Ranch Hand

Joined: Jan 05, 2012
Posts: 119
Hi

I have tried by servlet but still iam getting error.

Exception is : java.SQL.SQLException:After end of result set.

find .jsp


servlet


Web.xml:




iam having some username and password in my database if i gave username and click ok means it wants to show the password in inputfield.
it is same as finding option.

Please help me to solve my issue.

Thanks in advance.
S Subbu
Ranch Hand

Joined: Mar 20, 2012
Posts: 87

Hi Arun,

I can't understand your problem.What i understood is

You have User Name and Password in your database and have a jsp page that contains username and passwords input text fileds when you type user name and then click submit button you get the
password related to that username .

For this you have to use ajax.This is the better way . Leave ajax now do what i say


In Servlet Page




In Your JSP Page add value to input tags like

<td> First Name : </td><td> <input name="fname" size=15 type='text' id='fname' value='${request.fname}' /> </td><td> Last Name : </td><td> <input name="lname" size=15 type="text" id='lname' value='${request.lname}' /> </td>

EL Works if your jdk is greater than 5.0



P Arunkumar
Ranch Hand

Joined: Jan 05, 2012
Posts: 119
Hi

Thank you for your guide still iam facing problem.

Now iam not getting any error and iam getting my jsp page but still in my jsp page my username and password is not reflecting. please now iam giving my full code please check and guide me.


find.jsp page:



my servlet


web.xml



Now if i gave my username and click ok button it is coming to jsp page but from database it is not taking my username and password from database and not reflecting in jsp page input field.


Please help me in which place iam doing mistake.

Thanks in advance.
S Subbu
Ranch Hand

Joined: Mar 20, 2012
Posts: 87

I am Placing System.out.println() and observer the outputs

Please execute query in sql browser.(I placed query string in System.out.println()) execute That .




Check Web.xml after close <web-app> tag again pasted some mapping there.

P Arunkumar
Ranch Hand

Joined: Jan 05, 2012
Posts: 119
Hi

Thanks you for your reply.

From database it is taking username and password but that username and password is not showing in jsp input field.

Please understand my question, iam haveing one jsp page its having 2 fields one is username and password in database iam having some username and password. if i gave username and click ok means in username field it wants to show username and in password field it wants to take the password from database and that password wants to reflect in jsp page.

It is same as find option, data is taken from database but that data is not fetching in jsp page. iam running in eclipse in console tab it is showing the information but in jsp page in particular place it is not reflecting. i don't know that i want to keep one jsp page or 2jsp page.


Please guide me to solve my issue. please help me. to ask this doute also iam not having any member to help me in my office,iam developing alone please guide me.

Thanks in advance.
P Arunkumar
Ranch Hand

Joined: Jan 05, 2012
Posts: 119
Hi

i have finished the task but now iam facing one more problem.

While iam running my jsp page its showing null in input field,i know why its showing but i don't know how to solve my issue please help me. Iam passing my values in the jsp page for that resone its showing null but if i pass the values only from database its showing values in input filed . please help me.

My find.jsp page is



If you note in my jsp page i have given value="<%=request.getAttribute("user") %>" for that resone only its showing null values, then by using this line code only iam getting values from database in input field. please help me to avoid my issue.

My servlet code is:



i wants to use same jsp page to find the values it will be possible or not because for everythig we keep 2pages means its not a right way to develop, so iwants to use same jsp page.

please solve my issue, please guide me.

Thanks in advance.
S Subbu
Ranch Hand

Joined: Mar 20, 2012
Posts: 87

Hi Arun Good Job, For removing null you have to do

<input type="text" value="<%=(request.getAttribute("user")==null)?"":(String)request.getAttribute("user")%>">

but insteadof using scriptlet go for EL as

<input type="text" value="${user}">

My Suggestion is use EL is recommendded than scriptlet in your jsp page.

Go ahead keep it up.
P Arunkumar
Ranch Hand

Joined: Jan 05, 2012
Posts: 119
Thanks a lot. really iam so happy. i got my result.
S Subbu
Ranch Hand

Joined: Mar 20, 2012
Posts: 87

Ok Arun Good.

But I Strongly Recommended you use EL than Scriptlets . EL is Good Practice .


Please Spend Time On JSTL and EL ok Go ahead.
P Arunkumar
Ranch Hand

Joined: Jan 05, 2012
Posts: 119
Hi

Thanks you i have used EL only. Can you please provide me some sites regarding EL and JSTL.
S Subbu
Ranch Hand

Joined: Mar 20, 2012
Posts: 87

Follow Below Link

OnJava.com For JSTL and EL


Good Luck
Atul Darne
Ranch Hand

Joined: Jul 05, 2009
Posts: 118

this is an old way to add the JSP script to the page itself..
you must use a framework like struts and hibernate


Regards, Atul.
I came to this world on a Learner's License
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61433
    
  67

Atul Darne wrote:you must use a framework like struts and hibernate

Nonsense. No one must use a framework.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Retrive a single data from database and display that in jsp text box.